Last Updated: February 25, 2016
·
3.088K
· tomsabin

Cloning a MongoDB to Meteor's production servers

Suppose you have a deployed Meteor app through meteor deploy <appname> and you wish to use data found on some MongoDB (for this example we'll be using MongoHQ)

First of all you will need to find your Mongo URI. In MongoHQ, this is found in the admin/overview section and should look something like mongodb://<user>:<password>@<host>:<port>/<database>.

Next, use mongodump to grab a copy of this database and store it somewhere, locally, temporarily. We'll be saving it to the desktop:

mongodump --host <host>:<port> --db <database> -u <username> -p <password> -o ~/Desktop

(Replace <host>:<port>, <database>, <username> and <password> from the Mongo URI identified above.

Then, mongorestore will be used to copy this dumped database across to Meteor's production server. We need to find out the MongoDB details first, this can be easily done with the following input:

meteor mongo <appname>.meteor.com --url

Again, this will be returned as a Mongo URI (mongodb://<user>:<password>@<host>:<port>/<database>) and it is important that once you have this information that you run the following line as the username and password will change after some time:

mongorestore -u <user> -p <password> -h <host>:<port> -db <database> ~/Desktop/<database>

Your MongoDB data should now exist on Meteor's production servers! Note: this assumes that, if you have password protected your Meteor domain, that you have entered the authentication for this at the required steps.