How to fix mongorestore 'E11000 duplicate key error collection'
Problem:
You are trying to run mongorestore my-backup
, but you see large numbers of warning messages like this one:
- E11000 duplicate key error collection: mydb.mycollection index: _id_ dup key: { : "MyKey" }
Solution
By default, mongorestore
does not overwrite or delete any existing documents. You need to tell it to drop each collection immediately before importing it from the backup:
mongorestore --drop my-backup
Any documents not in the backup will be permanently lost after running this!
Note that this will not drop collections that are not present in the backup.
Also seeĀ mongodump/mongorestore minimal examples