Sheharyar Naseer

Sync MongoDB data between Development and Production databases

For a recent project of mine, I had to constantly copy my local MongoDB Database to and from my Production Heroku Database. Running mongodump and mongorestore again and again with complicated flags to support remote urls quickly became a hassle. I had previously used heroku-mongo-sync, but it is now deprecated in favor of marcofognog’s fork. Unfortunately, neither of them worked for me.

So I decided to write my own. Meet mongo-sync:

mongo-sync demo gif

It’s a simple shell script that allows you to sync your local and remote MongoDB databases, using two commands; push and pull. Start by cloning the script on your machine:

git clone
cd mongo-sync

Edit the provided config.yml with your db details:

  db: 'local_db_name'

  db: 'remote_db_name'
    url: ''
    port: 27017
    username: 'remote_mongo_user'
    password: 'remote_mongo_pass'

# For Heroku MongoDB URLs, here's the legend:
# mongodb://

Now, you can start syncing your databases:

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

I’m planning to convert it into a Ruby Gem and a Heroku Plugin as well.

Github: sheharyarn / mongo-sync


  • 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

Further Reading