Copy database from mlab to local database


#1

Like the title says, I am trying to copy my live database to my local database.
The live db is hosted on mlab.com.

It would be ideal if the copy process happened when I start the local meteor instance.
Any idea on how to do this?

cheers!
godo


#2

What’s your use case?

If you really need a local copy of the remote database, mlab gives you a ton of options for dumping the data, and you can either use cli to do something like mongorestore, or even a gui to import the data.

If you’re just trying to access the remote data with a local app, you can use MONGO_URL to connect to your mlab db.


#3

Hey vigor,

thanks for the reply.
What gui would you recommend for importing?
I use Robomongo, but it does not have any import tools :frowning:


#4

You can check out mongochef, which supports imports in a gui environment.


#5

Yes, there is. I’m occasionally using it to check reliable migrations of my live database before deploying updates.

You’ll find specific commands on the ‘Tools’ section of your database …

mongodump -h <host:port> -d <database> -u <username> -p <password> -o <output directory>
mongorestore -h <host:port> -d <database> -u <user> -p <password> <input db directory>

For large databases you can just set the MONGO_URL.

For small databases I run this locally. Run meteor reset first. then start meteor.
as soon as the mongo instance has started you can just run this before the application starts to connect to the database.

mongorestore -h localhost:3001 -d meteor <input db directory>

I’m sure that there is a way to clear a database during startup and then trigger the restore, but I’ve not needed that yet as it’s usually only a one off run shortly before deployment and the staging database I tend to use for that is pretty small.