iefpw
iefpw

Reputation: 7042

Copying MongoDB database from source

I'm trying to move a Mongo database from my local computer to a public networked Mongo server. The db.copydatabase says it needs to be run on the destination server, but in my case my computer doesn't have external IP set up so the destination server cannot connect to my computer through the internet. Is there a way to do this from my computer to a public server like run from the source instead of the destination? Can I also use backup or any techniques that work?

Upvotes: 1

Views: 280

Answers (1)

Sim
Sim

Reputation: 13528

The easiest way to copy the database if you do not have external access to the source machine is the following:

  1. Use mongodump to export the data.

  2. (Optional) If you are dealing with a lot of data, you may want to put the generated *.bson files close (from a network standpoint) to the destination MongoDB. The reason to do this is that the import operation (step 3 below) sometimes flakes out on poor network connections if you are moving more than 1Gb of data. If you control the destination database machine, put them there using whatever mechanism you prefer, e.g., secure copy (scp). If you do not control the destination machine, e.g., if you are using MongoHQ or MongoLab hosting, put them on a EC2 node in the same availability zone as the node with your MongoDB instance.

  3. Use mongorestore to load the data.

See MongoDB's docs on import/export tools.

Upvotes: 1

Related Questions