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

New update operator for compare-and-set pattern

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

      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.

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

              Created:
              Updated:
              Resolved: