Skip to content

mongorestore "E11000 duplicate key error collection"

Solved Configure
  • During the restore of a MongoDB based database, you may receive the error message

    E11000 duplicate key error collection

    This is because by default the mongorestore command does not drop existing collections before attempting to recover them, which results in the above error message as the collections already exist

    As an example, the command of

    sudo mongorestore -d sudonixdev /path/to/database/sudonix -u admin -p <password> --authenticationDatabase=admin
    

    Would need to become

    sudo mongorestore --drop -d sudonixdev /path/to/database/sudonix -u admin -p <password> --authenticationDatabase=admin
    

    The addition of --drop allows the collections to be overwritten by the restore.

  • phenomlabundefined phenomlab has marked this topic as solved on

Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation 💗

Related Topics