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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4021762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:50:53  来源:igfitidea点击:

MongoDB mongorestore and existing collection with records

mongodbmongorestore

提问by Simone Carletti

I need to import (restore) a collection generated with mongodumpinto an existing database and I'd like the records to be merged into the existing collection.

我需要将生成的集合导入(恢复)mongodump到现有数据库中,并且我希望将记录合并到现有集合中。

Does mongorestoremerge the records in the same collection or it will drop the existing collection before restoring the records?

是否mongorestore合并同一集合中的记录,或者在恢复记录之前会删除现有集合?

回答by Niels van der Rest

mongorestorewill only drop the existing collection if you use the --dropargument.

mongorestore如果您使用该--drop参数,则只会删除现有集合。

If you don't use --drop, all documents will be inserted into the existing collection, unless a document with the same _idalready exists. Documents with the same _idwill be skipped, they are not merged. So mongorestorewill never delete or modify any of the existing data by default.

如果您不使用--drop,则所有文档都将插入到现有集合中,除非_id已经存在相同的文档。相同的文件_id将被跳过,它们不会被合并。所以mongorestore默认情况下永远不会删除或修改任何现有数据。