Skip to content

mongorestore "E11000 duplicate key error collection"

Solved Configure
1 1 1.7k 1
  • wrote on last edited by
    #1

    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.

  • phenomlab phenomlab has marked this topic as solved on

Did this solution help you?
Did you find the suggested solution useful? Support 💗 Sudonix with a coffee ☕
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics
  • Mongo Completely Broken.

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

    General database mongodb redis
    29
    11 Votes
    29 Posts
    12k Views
    phenomlab
    @Madchatthew still a great catch.
  • Is my Mongodb installation correct?

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

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

    Configure mongodb docker ansible
    11
    2 Votes
    11 Posts
    4k Views
    phenomlab
    @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
    982 Views
    phenomlab
    @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 mongodb
    2
    1 Votes
    2 Posts
    1k Views
    DownPW
    @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 mongodb
    17
    2 Votes
    17 Posts
    5k Views
    phenomlab
    @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