Last Updated: February 25, 2016
·
2.382K
· sheharyar

Sync Local and Production MongoDB Data

mongo-sync demo gif

Start by cloning the mongo-sync on your machine:

git clone https://github.com/sheharyarn/mongo-sync.git
cd mongo-sync

Edit the provided config.yml with your db details:

local:
  db: 'local_db_name'

remote:
  db: 'remote_db_name'
  host:
    url: 'some.remoteurl.com'
    port: 27017
  access:
    username: 'remote_mongo_user'
    password: 'remote_mongo_pass'

# For Heroku MongoDB URLs, here's the legend:
# mongodb://username:password@hosturl.com:port/db_name

Now, you can start syncing your databases:

./mongo-sync push       # Push DB to Remote
./mongo-sync pull       # Pull DB to Local

Notes:

  • The push and pull commands overwrite the target DB
  • If you include this script into your project, it's a good idea to add config.yml to your .gitignore

<br/>

mongo-sync on Github

Original Blog Post