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
MongoDB mongorestore and existing collection with records
提问by Simone Carletti
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.
我需要将生成的集合导入(恢复)mongodump
到现有数据库中,并且我希望将记录合并到现有集合中。
Does mongorestore
merge the records in the same collection or it will drop the existing collection before restoring the records?
是否mongorestore
合并同一集合中的记录,或者在恢复记录之前会删除现有集合?
回答by Niels van der Rest
mongorestore
will only drop the existing collection if you use the --drop
argument.
mongorestore
如果您使用该--drop
参数,则只会删除现有集合。
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.
如果您不使用--drop
,则所有文档都将插入到现有集合中,除非_id
已经存在相同的文档。相同的文件_id
将被跳过,它们不会被合并。所以mongorestore
默认情况下永远不会删除或修改任何现有数据。