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

Easy syntax for $setIfModified behavior

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 4.2.0
    • Fix Version/s: Backlog
    • Component/s: Write Ops
    • Labels:
      None
    • Case:

      Description

      see SERVER-13578. This behavior is "possible" using update pipeline syntax released in 4.2, but it becomes extremely verbose for this common use case.

      Example 

      db.runCommand(
       {
       update: "test",
       updates: [
       {
       q: { a: 1 },
       u: [
       { $set: { a: 1, b: 2,
      created_at: {$cond: [
       {$eq:[ {$type:"$_id"}, "missing" ] },
       ISODate(),
       "$created_at"
       ] },
      updated_at: {$cond: [
       {$or: [
       $ne:["$a", 1],
       $ne:["$b", 2],
       ]},
       ISODate(),
       "$updated_at"
       ] }
      } },
       ],
       upsert: true
       }
       ],
       writeConcern: { w: "majority", wtimeout: 5000 }
       }
      )
      

       

      You can see that as the complexity of the document grows, the more verbose the command becomes to get this behavior. It would be nice to get this behavior with an easy to use operator (e.g. $setIfModified)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              nefiga Ben Rotz
              Participants:
              Votes:
              6 Vote for this issue
              Watchers:
              11 Start watching this issue

                Dates

                Created:
                Updated: