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

后端 未结 3 582
忘了有多久
忘了有多久 2021-02-05 21:50

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

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-05 22:37

    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

    mongo-sync demo gif

提交回复
热议问题