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?
However, mongorestore performs inserts only and does not perform updates. That is, if restoring documents to an existing database and collection and existing documents have the same value _id field as the to-be-restored documents, mongorestore will not overwrite those documents.
Overwrite Filesmongodump overwrites output files if they exist in the backup data folder. Before running the mongodump command multiple times, either ensure that you no longer need the files in the output folder (the default is the dump/ folder) or rename the folders or files.
Run the MongoDB mongodump command to create a dump file of any specific database or collection. Run the mongorestore command to restore the dump file into any MongoDB instance. Choose either the original MongoDB instance that the backup was created for, or any alternative instance.
mongoexport is a command-line tool that produces a JSON or CSV export of data stored in a MongoDB instance. mongodump is a utility for creating a binary export of the contents of a database.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With