Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-2191

undocumented behaviour or bug of db.collection.save (E11000 duplicate key error)

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 01112017-cleanup
    • None
    • None
    • None

    Description

      Hello,

      recently I created a question in stackoverflow http://stackoverflow.com/questions/19787803/mongo-throws-e11000-duplicate-key-error-whey-i-try-to-do-db-collection-save-oper?noredirect=1#comment29414789_19787803

      related to behaviour of function db.collection.save when I try to do insert/replace chunk of documents.

      I created the scenario

      > use sometestdb
      switched to db sometestdb
      > 
      > doc1 = { _id: 1, value: "some value 1" }
      { "_id" : 1, "value" : "some value 1" }
      > doc2 = { _id: 2, value: "some value 2" }
      { "_id" : 2, "value" : "some value 2" }
      > doc3 = { _id: 3, value: "some value 3" }
      { "_id" : 3, "value" : "some value 3" }
      > 
      > db.docs.save( [doc1, doc2, doc3] )
      > 
      > doc1 = { _id: 1, value: "some value 1 - updated" }
      { "_id" : 1, "value" : "some value 1 - updated" }
      > doc2 = { _id: 2, value: "some value 2 - updated" }
      { "_id" : 2, "value" : "some value 2 - updated" }
      > doc3 = { _id: 3, value: "some value 3 - updated" }
      { "_id" : 3, "value" : "some value 3 - updated" }
      > db.docs.save( [doc1, doc2, doc3] )
      E11000 duplicate key error index: sometestdb.docs.$_id_  dup key: { : 1.0 }

      The documentation does no say anything about using array of documents. Is it bug or ambiguous documentation?

      Thank you, JM

      Attachments

        Activity

          People

            sam.kleinman Sam Kleinman (Inactive)
            Jaromir Muller Jaromir Muller [X]
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 15 weeks ago