MongoDB mongorestore和具有记录的现有集合


80

我需要将生成的集合导入(还原)mongodump到现有数据库中,并且我希望将记录合并到现有集合中。

是否mongorestore合并的记录相同的集合中,否则将恢复记录之前删除现有的收藏?

Answers:


130

mongorestore如果使用该--drop参数,则只会删除现有集合。

如果不使用--drop,则所有文档都将插入到现有集合中,除非_id已经存在具有相同文档的文档。具有相同文档的文档_id将被跳过,不会被合并。因此mongorestore,默认情况下永远不会删除或修改任何现有数据。


使用选项--drop实际删除了mongodb吗?在我的情况下,在还原时,我可以看到进行转储后添加的先前记录。你可以在这里解决我的问题stackoverflow.com/questions/22424347/...
— codeofnode


4
文档中的@codeofnode :--drop does not drop collections that are not in the backup.。您应该验证备份中是否确实存在您希望删除的集合。
— csvan 2015年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.