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

Collections created by an update write command don't get an _id_ index

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.5.4
    • None
    • None
    • ALL

    Description

      If the first document in a collection is upserted using the new update command subsequent duplicate _id inserts succeed:

      > db.dropDatabase()
      { "dropped" : "foo", "ok" : 1 }
      > 
      > db.runCommand({update: 'bar', updates: [{q: {_id: 1}, u: {}, upsert: true}]})
      { "ok" : 1, "n" : 1, "upserted" : 1 }
      > db.bar.insert({'_id': 1})
      > db.bar.insert({'_id': 1})
      > db.bar.insert({'_id': 1})
      > db.bar.insert({'_id': 1})
      > 
      > db.bar.find()
      { "_id" : 1 }
      { "_id" : 1 }
      { "_id" : 1 }
      { "_id" : 1 }
      { "_id" : 1 }

      The new insert command does not cause the same problem:

      > db.dropDatabase()
      { "dropped" : "foo", "ok" : 1 }
      > db.runCommand({insert: 'bar', documents: [{_id: 1}]})
      { "ok" : 1, "n" : 1 }
      > db.bar.insert({'_id': 1})
      E11000 duplicate key error index: foo.bar.$_id_  dup key: { : 1.0 }

      Attachments

        Activity

          People

            Unassigned Unassigned
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: