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
  • Mongo Completely Broken.

    General
    20
    3 Votes
    20 Posts
    436 Views
    @Sampo2910 said in Mongo Completely Broken.: I can see you cringing Yes, that does make me slightly uncomfortable but OK.
  • Mongodb or Redis

    General
    29
    11 Votes
    29 Posts
    729 Views
    @Madchatthew still a great catch.
  • Is my Mongodb installation correct?

    Solved General
    27
    4
    13 Votes
    27 Posts
    3k Views
    [image: 1711303116154-yuuuuu.png]
  • mongodb backup problem

    Moved Configure
    3
    1
    1 Votes
    3 Posts
    292 Views
    You might want to also review this post https://sudonix.org/topic/389/mongodb-backup-script
  • mongodb replica set

    Configure
    11
    2 Votes
    11 Posts
    586 Views
    @veronikya said in mongodb replica set: The host’s local dns resolution is not configured. The problem of the host’s hosts being unable to be resolved in docker has been solved. Surprisingly Solution: Edit the /etc/resovel.conf file Add 127.0.0.53 One immediate issue I can think of here is that editing resolv.conf directly is no longer supported and not recommended (because the changes do not survive a reboot) - unless you install the resolvconf package?
  • 3 Votes
    2 Posts
    218 Views
    @DownPW This isn’t something I have readily available, and because I’m not entirely familiar with the database structure of NodeBB, it’s something that would require research and development in terms of script. I think it’d be quicker to ask this in the NodeBB forums.
  • Nodebb: failed to restore a mongo dump

    Solved Configure
    2
    1 Votes
    2 Posts
    245 Views
    @phenomlab In fact I specified the sub rep and not the rep DON’T DO THIS: nodebb@nodebbpwclonedb:~/nodebb$ sudo mongorestore --username admin --password XXXXXXXXXXXXXX --nsInclude nodebb.objects --drop /home/nodebb/nodebb_DB_20230107/nodebb/ BUT THIS : nodebb@nodebbpwclonedb:~/nodebb$ sudo mongorestore --username admin --password XXXXXXXXXXXXXX --nsInclude nodebb.objects --drop /home/nodebb/nodebb_DB_20230107/
  • Mongodb Authorisation.

    Solved General
    17
    2 Votes
    17 Posts
    891 Views
    @Sampo2910 I just saw this on the NodeBB community site and it seems very much in line with the issue you are experiencing. Worth a look I think https://community.nodebb.org/topic/16826/does-nodebb-work-with-mongodb-6-0