将mongo集合导入到现有集合中而不覆盖它 [英] Importing mongo collection into existing collection without overriding it

查看:1123
本文介绍了将mongo集合导入到现有集合中而不覆盖它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将mongodump导入添加到其中的现有集合中(而不是覆盖它)?如果是,怎么办?

Is it possible to import a mongodump into a existing collection adding to it (not overriding it)? If yes, how?

会使用mongoimport --db mydb吗?

集合的结构相同,但简单的是来自同一应用程序不同实例的不同数据集.我想将所有数据合并到一个数据库中.

The collections are the same in structure but simple have different datasets from different instances of the same app. I'd like to merge all data into a single database.

推荐答案

使用 mongorestore .

仅当您指定 --drop时,它才会覆盖集合参数.因此,如果您什么也不做,只会添加新的元素(因此可以执行您想要的操作).

It is overwriting the collection only if you specify --drop parameter. So if you do nothing it will just add new element (thus doing what you want).

如果您具有相同的_id元素,则可能会出现唯一的问题,在这种情况下,它只会忽略它们.

The only problem might arise if you have the same _id elements, in which case it will just ignore them.

如果还原到现有数据库,则mongorestore将仅插入 到现有数据库中,并且不执行任何类型的更新. 如果现有文档在目标中具有相同的值_id字段 数据库和集合,mongorestore不会覆盖那些 文档.

If you restore to an existing database, mongorestore will only insert into the existing database, and does not perform updates of any kind. If existing documents have the same value _id field in the target database and collection, mongorestore will not overwrite those documents.

这篇关于将mongo集合导入到现有集合中而不覆盖它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆