mongorestore command replace existing records?

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.


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.

If you want to completely overwrite the database or a collection within the database with mongorestore, drop the database or collection (check --drop parameter as pointed out by vikas's answer). If you want to replace certain documents or merge duplicate documents, then you'll need to write your own script to do the restore and implement the more complex logic yourself.

Tags:

Mongodb