MongoDB mongorestore and existing collection with records

MongodbMongorestore

Mongodb Problem Overview


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.

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

Mongodb Solutions


Solution 1 - Mongodb

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSimone CarlettiView Question on Stackoverflow
Solution 1 - MongodbNiels van der RestView Answer on Stackoverflow