Mongorestore to update records if already exists without --drop
The first case is true. Mongorestore does not update documents if already exist. It skips those documents when restoring.In your second case, please try using mongoimport with --upsert option. It will merge the records if _id already exists.
Example:
mongoimport --db dbname --collection collname --upsert --file file.json
Please vote for this ticket to add an upsert
option to mongorestore.
Until that is implemented, we have found a workaround:
- Dump Collection From Server A ( original )
- Dump Collection From Server B ( target )
- Restore With Drop Collection A on Server B 4
- Restore Without Drop Collection B on Server B
In this case updated document will not overwritten