New update operator for compare-and-set pattern

XMLWordPrintableJSON

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

      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 - Query Team (Inactive)
            Reporter:
            JianXiong Zhou [X]
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: