Solved mongorestore "E11000 duplicate key error collection"


  • 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.

  • Topic has been marked as solved  phenomlab phenomlab 

If this thread resolved an issue for you, or was useful, why not buy me a coffee? It's a nice gesture, and there's other ways to donate if you wish 💗

Discover More