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

Upsert atomicity confusion

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Concurrency, Storage
    • None

      There is some confusion about upsert behaviour and its atomicity.

      Given the following write :

      db.col.update({a:1, b:1}, {$inc: {c:1}}, true)
      

      The expectation is that there should never be more than one document in the database with

      {a:1, b:1}

      in the collection. Now recently this line was added to the "Warning To avoid inserting the same document more than once, only use upsert: true if the query field is uniquely indexed.". This seems to apply that without such a unique index this behaviour is no longer guaranteed.

      Questions :

      1) Is this unique index needed and if so why (isn't this atomicity guaranteed by the write lock?)
      2) Is the current behaviour different from earlier versions and if so, when has this changed.

            Assignee:
            Unassigned Unassigned
            Reporter:
            remonvv Remon van Vliet
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: