I have a web application with production data running on a Cidar stack in Heroku. The production data is stored in a MongoDB and I use MongoHQ to manage it in production. I'd like to download the production data to my local machine so I can run my web app locally with production data for debugging purposes. I'm still relatively new to MongoDB, so after many attempts, I've had no success.
Is there a way to download MongoDB data (collections) from Heroku to a local MongoDB I have on my local machine?
I figured it out, thanks to this blog post: http://stevespiga.rel.li/mongodump-mongorestore.html
Here a summary of the solution:
heroku config | grep "MONGOHQ"
. This gave me output of the form:MONGOHQ_URL:mongodb://heroku:veryLongPasswordString@somewhere.mongohq.com:88888/app123456
.
MONGOHQ_URL:mongodb://username:password@host:port/path
mongodump --db <path> --host <host> --port <port> --username <username> --password <password> --out <folder for dump>
.
mongodump --db app123456 --host somewhere.mongohq.com --port 88888 --username heroku --password veryLongPasswordString --out ./testDump
.
mongorestore ./testdump
.
Note, this assumes that you do NOT have a local db of the same name as the dumped db before you restore. If need be you can rename the db by following the steps outlined in this stackoverflow post.
I hope this helps!