MongoDB mongorestore and existing collection with records
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.
Simone Carletti
Hi! My name is Simone Carletti. I'm a passionate programmer and scuba diving instructor. I'm the CTO at DNSimple. I created RoboWhois and RoboDomain. I have been involved with software development for more than a decade, contributing code and creating libraries.
Updated on July 10, 2022Comments
-
Simone Carletti almost 2 years
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? -
codeofnode over 10 yearsis the mongodb actually being dropped with using option --drop? In mine case, on restore, i can see the previous records that was added after taking the dump. can you solve my issue here stackoverflow.com/questions/22424347/…
-
Tomas Romero almost 10 yearsMongorestore ref for the answer above: docs.mongodb.org/manual/reference/program/mongorestore/…
-
csvan over 8 years@codeofnode from the documentation:
--drop does not drop collections that are not in the backup.
. You should verify that the collection you expect to be dropped is indeed present in the backup.