[SERVER-36522] Create Index showing duplicate key error Created: 08/Aug/18  Updated: 27/Oct/23  Resolved: 08/Aug/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Ryan Joseph Assignee: Nick Brewer
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Backport Requested:
v3.6
Participants:

 Description   

When I try to create an Index I get:

MongoDB Enterprise PRIMARY> db.col.createIndex( { "Content._id": 1 }, {unique : true } )
{
        "operationTime" : Timestamp(1533699325, 1),
        "ok" : 0,
        "errmsg" : "E11000 duplicate key error collection: db.col index: Content._id_1 dup key: { : null }",
        "code" : 11000,
        "codeName" : "DuplicateKey",
        "$clusterTime" : {
                "clusterTime" : Timestamp(1533699325, 1),
                "signature" : {
                        "hash" : BinData(0,"8H8uDcd1rDYdqnXH/zX/Qul1uz8="),
                        "keyId" : NumberLong("6551211271260209154")
                }
        }
}

I can't find any existing Indexes with same name:

MongoDB Enterprise PRIMARY> db.col.dropIndex( { "Content._id": 1 })
{
        "nIndexesWas" : 2,
        "ok" : 0,
        "errmsg" : "can't find index with key: { Content._id: 1.0 }",
        "code" : 27,
        "codeName" : "IndexNotFound",
        "operationTime" : Timestamp(1533699815, 1),
        "$clusterTime" : {
                "clusterTime" : Timestamp(1533699815, 1),
                "signature" : {
                        "hash" : BinData(0,"NMKXIv/5UI2eh1ip3CnEuRrx8cQ="),
                        "keyId" : NumberLong("6551211271260209154")
                }
        }
}

Or find duplicate indexes with value of null:

MongoDB Enterprise PRIMARY> db.Users.find( { "Content._id": null })
MongoDB Enterprise PRIMARY>

Would someone know what else would prevent me from creating that index?  On my localhost instance, I can create the index without any problems.  Any help would be greatly appreciated.

 

 

 

 



 Comments   
Comment by Ryan Joseph [ 08/Aug/18 ]

Thank you Nick.  I'll check out those resources.

Comment by Nick Brewer [ 08/Aug/18 ]

ryan.vi.joseph@gmail.com Per the unique index documentation, what you're running into is a constraint of using a unique index with multiple documents that do not match it.

For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag.

-Nick

Comment by Ryan Joseph [ 08/Aug/18 ]

List of existing indexes:

MongoDB Enterprise PRIMARY> db.col.getIndexes()
[
        {
                "v" : 2,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "db.col"
        },
        {
                "v" : 2,
                "unique" : true,
                "key" : {
                        "Email" : 1
                },
                "name" : "_email",
                "ns" : "db.col"
        }
]

Generated at Thu Feb 08 04:43:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.