-
Type:
Question
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
I am facing a duplicate key exception intermittently when trying to upsert an existing document.
- Exception
E11000 duplicate key error collection: userprofiledb.userProfile index: _id_ dup key: { : "9441959569" }; nested exception is com.mongodb.MongoWriteException: E11000 duplicate key error collection: userprofiledb.userProfile index: _id_ dup key: { : "9441959569" }
- Indexes on the document:
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "userprofiledb.userProfile"
}
]
- Query is like so: (Its an upsert query with replace document, the "u" part of the query doesnt contain _id key)
{
"update":"userProfile",
"ordered":true,
"updates":[
{
"q":{
"_id":"9711665996"
},
"u":{
"key1":"value1",
"key2":"value2",
"key3":[
"value3a",
"value3b",
"value3c"
]
},
"upsert":true
}
]
}
- There is a document exisiting with this _id so this is an upsert case and not an insert case like [mentioned here](https://jira.mongodb.org/browse/SERVER-21006?focusedCommentId=1065415&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1065415)
Is there any other possible sequence of events where we can get duplicate key exception.