Copy mongodb collection between two servers AND different mongo versions …

mongodb

I have a collection in a mongoDB, on a project that runs locally, and have to copy the collection to the dev server. Can you tell me how to do this, considering that:

  1. The local machine (the source) is accessible from the outside, but only with the IP.

  2. The version of the local mongo is 2.0.4, while the version of mongo on the dev server is 2.2.2.

I made a little research, but I'm not sure for some things … like for example which credentials should I choose for the source DB ? … the ones for SSH connection? … or … ? …

Thanks in advance 🙂

Best Answer

You can create another connection from the destination server and use the save() function.

For example:

conn2 = new Mongo( "desitination_server:port")

desti_db = conn2.getDB( "destination_db_name" ) --> now you can access destination mongodb server from source DB connection.

db.sourceCollection.find().forEach( function(x){ desti_db.targetCollectionName.save(x) } ); --> read current source DB collection and save it in destination mongodb

Related Topic