Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-59119

Intermittent Duplicate key exception on upserting an existing document

    XMLWordPrintableJSON

Details

    • Icon: Question Question
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      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
            }
         ]
      }
      

       

       

      Is there any other possible sequence of events where we can get duplicate key exception.

       

       

       

      Attachments

        Activity

          People

            eric.sedor@mongodb.com Eric Sedor
            rahul.jangra@airtel.com Rahul Jangra
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: