How to copy a collection from one database to another in MongoDB

前端 未结 19 1575
無奈伤痛
無奈伤痛 2020-11-28 00:22

Is there a simple way to do this?

19条回答
  •  难免孤独
    2020-11-28 01:03

    I know this question has been answered however I personally would not do @JasonMcCays answer due to the fact that cursors stream and this could cause an infinite cursor loop if the collection is still being used. Instead I would use a snapshot():

    http://www.mongodb.org/display/DOCS/How+to+do+Snapshotted+Queries+in+the+Mongo+Database

    @bens answer is also a good one and works well for hot backups of collections not only that but mongorestore does not need to share the same mongod.

提交回复
热议问题