How to use mongodump for 1 collection

后端 未结 4 778
小蘑菇
小蘑菇 2021-01-30 00:58

How can I use mongodump to move a single collection from one database to another?

How should I use the command and its options?

4条回答
  •  佛祖请我去吃肉
    2021-01-30 01:23

    I think it's just:

    mongodump --db= --collection= --out=data/
    
    mongorestore --db= --collection= data//.bson
    

    Also see docs here and here.

    Btw, the other way to move the collection from one database to another is to use renameCollection:

    db.runCommand({renameCollection:".",to:"."})
    

    Here's some related SO threads:

    • How to copy a collection from one database to another in MongoDB
    • How to use the dumped data by mongodump?

    Hope that helps.

提交回复
热议问题