Skip to content

Instantly share code, notes, and snippets.

@devender-yadav
Created May 22, 2019 17:28
Show Gist options
  • Save devender-yadav/f3e5c4d86fef7ed181074628f08996e4 to your computer and use it in GitHub Desktop.
Save devender-yadav/f3e5c4d86fef7ed181074628f08996e4 to your computer and use it in GitHub Desktop.
Merge mongo data distributed on 2 locations

Let us assume, initally mongo is using /data/db1 dbpath and then /data/db2

Start mongo /data/db1

sudo mongod --dbpath=/data/db1

Export data from mongo /data/db1

mongoexport --db test_db --collection collection1 --out tb_collection1_db1.json

Start mongo /data/db2

sudo mongod --dbpath=/data/db2

Import data from mongo /data/db1

mongoimport --db test_db --collection collection1 --file tb_collection1_db1.json

All done!

Start Mongo Shell

mongo

>use test_db
>db.collections.count()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment