mongodb – remote copy of database

Connect with

There are different way of copying of data from one server to another or from one cluster to another cluster.

by using mongodump utility tool you can view another article : How to move data from staging server to production server of mongodb

By using db.copyDatabase() on terminal

run the following after logged-in into mongodb server.



## fileName: ####

#Sync mongodb database from remote to local where you run this.
#NOTE: be careful this overwrites the local copy (from where run) of the database if you have.
## here local means where you run this script, and remote means from where you want to get data .


mongo $localDb --eval "use '$localMongoDB'; db.dropDatabase(); db.copyDatabase('$remoteMongoDB', '$localMongoDB', '$remoteHost', '$remoteUserDB', '$remoteDBPasswd')"

By using db.copyDatabase() on mongos terminal

Syntax to copy database as:

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

example of copyDatabase()

>db.copyDatabase('orderdb', 'orderdb', '')

By using db.cloneCollection() on mongos terminal

>db.cloneCollection('', 'orderdb.orderColl');

Write your comment to improve this post. Happy Learning 🙂

Connect with

Leave a Reply

Your email address will not be published. Required fields are marked *