For a recent project of mine, I had to constantly copy my local MongoDB Database to and from my Production Heroku Database.
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
It’s a simple shell script that allows you to sync your local and remote MongoDB databases, using two commands;
Start by cloning the script 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:firstname.lastname@example.org:port/db_name
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
pullcommands overwrite the target DB
- If you include this script into your project, it’s a good idea to add