Importing mongo collection into existing collection without overriding it

好久不见. 提交于 2019-12-08 08:24:35

问题


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

Would it be using 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.


回答1:


Use mongorestore.

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).

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

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.



来源:https://stackoverflow.com/questions/29740348/importing-mongo-collection-into-existing-collection-without-overriding-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!