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
Post a Comment