MongoDB mongorestore和具有记录的现有集合 [英] MongoDB mongorestore and existing collection with records
问题描述
我需要将用mongodump
生成的集合导入(还原)到现有数据库中,我希望将记录合并到现有集合中.
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.
mongorestore
是将记录合并到同一集合中,还是会在还原记录之前删除现有集合?
Does mongorestore
merge the records in the same collection or it will drop the existing collection before restoring the records?
推荐答案
mongorestore
仅在使用--drop
参数时才会删除现有集合.
mongorestore
will only drop the existing collection if you use the --drop
argument.
如果不使用--drop
,则所有文档都将插入到现有集合中,除非已经存在具有相同_id
的文档.具有相同_id
的文档将被跳过,它们不会合并.因此,mongorestore
默认情况下永远不会删除或修改任何现有数据.
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.
这篇关于MongoDB mongorestore和具有记录的现有集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!