Is there a way for mongorestore to replace the records existing in the database instead of skipping it which is the default behavior ?
I'm currently using the latest 2.4.x version of mongodb.
No. From mongorestore: If you restore to an existing database, mongorestore will only insert into the existing database, and does not perform updates of any kind. If existing documents have the same value _id field in the target database and collection, mongorestore will not overwrite those documents.
The mongorestore command is the sister command of the mongodump command. You can restore the dumps (backups) created by the mongodump command into a MongoDB instance using the mongorestore command. In this article, you will learn how to utilize the mongorestore command to restore database backups effectively.
Database backup is a copy of a database that already exists. In MongoDB, mongodump tool is used to take the data backup. And mongorestore tool is used to restore the backup data.
You should just be able to do mongorestore --gzip <path to gzip folder). Side note you can use mongodump with --gzip option and it will compress it for you.
You could use the --drop
parameter of mongorestore
:
Before restoring the collections from the dumped backup, drops the collections from the target database. --drop does not drop collections that are not in the backup.
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