MongoDB mongorestore 和现有的带记录的集合

我需要导入(恢复)一个集合与 mongodump生成到一个现有的数据库,我想要的记录被合并到现有的集合。

mongorestore是合并同一集合中的记录,还是在还原记录之前删除现有集合?

38253 次浏览

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.