0

I have read few posts on StackOverflow regarding the cloneCollection database command. It indeed works just fine from the shell.

But is there a way to run the cloneColection using the C# Mongo Client?

I've tried:

local_database.RunCommand<BsonDocument>("{ cloneCollection : \"<collection>\", from: \"<server>:27017\" }"

I do get an Ok response, but nothing happens...

NirMH
  • 4,769
  • 3
  • 44
  • 69
  • Possible duplicate of [Duplicate a mongodb collection](https://stackoverflow.com/questions/19494066/duplicate-a-mongodb-collection) – Isma Jul 12 '18 at 12:02

1 Answers1

0

After digging around here is the right syntax to run the administrative command using the C# client...

var command = new BsonDocumentCommand<BsonDocument>(new BsonDocument(new List<BsonElement>()
{
    new BsonElement("cloneCollection", "<database_name>.<collection_name>"),
    new BsonElement("from", "<server_ip>:27017"),
    new BsonElement("query", "{}")
}
));
local_database.RunCommand<BsonDocument>(command);
NirMH
  • 4,769
  • 3
  • 44
  • 69