MongoDB mongorestore 和现有记录集合

发布于 2024-09-28 21:36:54 字数 138 浏览 8 评论 0原文

我需要将使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠魁 2024-10-05 21:36:54

如果您使用 --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. So mongorestore will never delete or modify any of the existing data by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文