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

Upsert atomicity confusion

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Concurrency, Storage
    • Labels:
      None

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: