MongoDB synchronize Development and Production databases MongoDB synchronize Development and Production databases mongodb mongodb

MongoDB synchronize Development and Production databases


You can use the mongoexport tool to export the single collection from your development database. Use it in conjunction with a --query option where you can express a predicate. For example something such as ${ts : {$gt : previous clone time}}.

Then, use mongoimport to import your delta file into production database. Use --upsert and --upsertFields if you have two different logical documents with different _id values, but express the same document


@Orid, thanks for your answer, and sorry for the late reply.

After a lot of research and some trial-error, I decided to use the solution stated in the question (Copy test DB to machine, and then copy the collections one by one).This is because the data I'm using here is static data, that doesn't have a real reason to have a timestamp.Also, I've decided to waive the requirement for "only updating", so for now I'm using mongorestore with --drop

I do all this using this script:

  1. The shell script file:

rm -rf dump/;

mongo copyTestDb.js;for COLLECTION in <Collections>domongodump -d nutrino_copy -c $COLLECTION -o dumpmongorestore -d nutrino -c ${COLLECTION} --drop dump/nutrino_copy/${COLLECTION}.bsondone
  1. The js script file:

    db.copyDatabase("<dbName>","<dbName_Copy>","<testMachineUrl>")

Do you think I should use MongoImport instead of MongoRestore?


Check out mongo-sync


It's a script I wrote for my self when I had to constantly copy my Local MongoDB database to and from my Production DB for a Project (I know it's stupid).

Once you put your DB details in config.yml, you can start syncing using two simple commands:

./mongo-sync push       # Push DB to Remote./mongo-sync pull       # Pull DB to Local

If you use it inside some project, it's a good idea to add config.yml to .gitignore


mongo-sync demo gif