Search code examples
mongodbmongodb-.net-driver

MongoDB commands from DOS or Windows


I'm trying to copy 4 collections from one Mongo database to another on the same machine from C# program automatically. How do I do that? Is there a simple copy collection/database command in MongoDB C# driver? or do I have to use the Mongo shell by first typing the ./mongo? If so how do I do that inside a MS-DOS command line window? Like ./mongo -copycollection from to?


Solution

  • Use mongodump, Type:

    ./mongodump --db your_db_name --collection collection_name  
    

    and then mongorestore:

    ./mongorestore --db=new_db_name
    

    Read more: mongodump and mongorestore