1. Home
  2. MongoDB
  3. MongoDB Tutorial
  4. MongoDB – Copy Database

MongoDB – Copy Database

MongoDB Copy Database

Use copyDatabsae() function to copy MongoDB database from remote database instance to local database instance. You can also use this to copy database in the local instance as alternatives for rename database.


db.copyDatabase(fromdb, todb, fromhost, username, password, mechanism)


Copy Database on Same Instance

You can create a duplicate database in same instance by using copyDatabase() function.



{ "ok" : 1 }

Also you can use above option to rename database in MongoDB. But you must have enough space to create a copy of an existing database with a different name. After that, you can remove the old database to release space.

Copy Database from Remote Instance

You can also use copyDatabase() function to copy the database from remote MongoDB instance to local database instance.


The above command will show a large output on your screen as per available documents in the database.

Tags , ,