How to perform one-time DB sync to another DB in MongoDB?

牧云@^-^@ 提交于 2019-12-20 12:26:43

问题


I have separate development and production MongoDB servers and I want to keep actual data in development server for sometime. What I should use for it: mongodump, mongoimport or something else?

Clarification: I want to copy data from production to development.


回答1:


You can use the db.copyDatabase(...) or db.cloneDatabase(...) commands:

http://www.mongodb.org/display/DOCS/Copy+Database+Commands

This is faster than mongodump / mongorestore because it skips creating the bson representation on disk.




回答2:


If it's a one time-thing

and you want fine control over parameters such as which collections to sync, you should use:

  • mongodump to dump bson files of your Production DB to your local machine
  • mongorestore to then, retrieve the dumped BSON files in your Local DB

Otherwise you should 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




回答3:


When you want the dev database to look exactly like the production database, you can just copy the files. I am currently running a setup where I synchronize my MongoDB database between my desktop and my notebook with dropbox - even that works flawless.



来源:https://stackoverflow.com/questions/12419181/how-to-perform-one-time-db-sync-to-another-db-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!