What is a proper way to duplicate a collection in Mongodb on the same server using C#? MongoVUE has an option \'Duplicate collection\', is there something similar for C#?
There isn't a built-in way to copy collections with the C# driver, but you can still do it pretty simply as:
var source = db.GetCollection("test");
var dest = db.GetCollection("testcopy");
dest.InsertBatch(source.FindAll());
Note, however, that this won't copy any indexes from the source collection. The shell's copyTo
method has the same limitation so it's likely implemented similarly.