Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongorestore command replace existing records?

Tags:

mongodb

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.

like image 509
Albert Gan Avatar asked Dec 27 '14 11:12

Albert Gan


People also ask

Does Mongorestore overwrite data?

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.

What is Mongorestore command?

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.

What is Mongodump and Mongorestore?

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.

How do I restore a .GZ file in MongoDB?

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.


1 Answers

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.

like image 169
vikas.sriv14 Avatar answered Sep 23 '22 05:09

vikas.sriv14