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

New update operator for compare-and-set pattern

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Do
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Querying, Write Ops
    • Labels:
      None

      Description

      Would mongodb provide a new update operator to make compare-and-set updates? Something like:

          { "$cond" : { "foo": [ oldValue, newValue ] } }
      

      mongodb set `newValue` to the "foo" field only when the original value of "foo" is equal to `oldValue`.

      Further more, the `oldValue` could be a boolean expression with the original value, and mongodb updates if the condition is true:

          // if (doc.foo != 1) { doc.foo = 2; }
          { "$cond" : { "foo": [ {"$ne": 1}, 2 ] } }
      

      There are already two similar operators: $min and $max, so I think this enhancement should be possible as well.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-server-query Backlog - Query Team (Inactive)
              Reporter:
              X JianXiong Zhou [X]
              Participants:
              Votes:
              4 Vote for this issue
              Watchers:
              11 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: