MongoDB mongorestore 和现有记录集合
我需要将使用 mongodump
生成的集合导入(恢复)到现有数据库中,并且希望将记录合并到现有集合中。
mongorestore
是否合并同一集合中的记录,或者在恢复记录之前会删除现有集合?
I need to import (restore) a collection generated with mongodump
into an existing database and I'd like the records to be merged into the existing collection.
Does mongorestore
merge the records in the same collection or it will drop the existing collection before restoring the records?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
--drop
参数,mongorestore
只会删除现有集合。如果不使用
--drop
,所有文档都将插入到现有集合中,除非已存在具有相同_id
的文档。具有相同_id
的文档将被跳过,不会合并。因此,mongorestore
默认情况下永远不会删除或修改任何现有数据。mongorestore
will only drop the existing collection if you use the--drop
argument.If you don't use
--drop
, all documents will be inserted into the existing collection, unless a document with the same_id
already exists. Documents with the same_id
will be skipped, they are not merged. Somongorestore
will never delete or modify any of the existing data by default.