mongodb - How to copy mongo database with all it's collection using c# driver? -


i trying copy mongo database using copydb command using c# driver. it's create target db no collection inside. when run command directly mongo shell work fine.

these c# code:

var db = mongo.getserver().getdatabase("admin"); var command = new commanddocument(new bsonelement("copydb", 1),                                   new bsonelement("fromdb", "db1"),                                   new bsonelement("todb", "db2")                                  ); var result = db.runcommand(command); 

its not copy collections of db1.

these command run mongo shell , work fine:

db.runcommand({copydb:1, fromdb:"db1", todb:"db2"}) 

what missing?

try following :

var result = db.runcommand(             new commanddocument(new bsonelement("copydb", 1),                 new bsonelement("fromhost", "localhost"),                 new bsonelement("fromdb", "sourcedb"),                 new bsonelement("todb", "targetdb"))); 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -