2

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?

2 Answers2

2

I figured it out, thanks to this blog post: http://stevespiga.rel.li/mongodump-mongorestore.html

Here a summary of the solution:

  1. I ran the command: heroku config | grep "MONGOHQ". This gave me output of the form:

MONGOHQ_URL:mongodb://heroku:veryLongPasswordString@somewhere.mongohq.com:88888/app123456.

  1. This can be interpreted as:

MONGOHQ_URL:mongodb://username:password@host:port/path

  1. Then I dumped the production db to a local directory by running:

mongodump --db <path> --host <host> --port <port> --username <username> --password <password> --out <folder for dump>.

  1. Example:

mongodump --db app123456 --host somewhere.mongohq.com --port 88888 --username heroku --password veryLongPasswordString --out ./testDump.

  1. The next step is to take the dumped data and restore it to your local database:

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!

Community
  • 1
  • 1
0

If you open up the MongoHQ dashboard ($ heroku addons:open mongohq) there's an option to create a backup and download it from there.

rdegges
  • 32,786
  • 20
  • 85
  • 109
  • I've gone to the dashboard as you suggested and after much searching, I still could not location an option to create a backup. I am using the free version of MongoHQ -- is backup disabled for that version maybe? @rdegges – The Traveling Coder Feb 09 '15 at 15:47