Conditional $set, ie $setIfBigger, $setIfSmaller etc in conjunction with upsert

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • None
    • Environment:
      All applicable
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The idea is that one should be able to do conditional upsert along the lines of:

      var current_value = "some nifty complex calculation"

      db.dbname.update(

      { attr1 : value1, attr2 : value2}

      ,
      {"$inc" :

      { avg : current_value, nr : 1}

      ,
      "$setIfBigger" : { max : current_value}},
      false (multi), true (upsert))

      Currently if you want to do the above you have to check if such an object exists, and if if does update it, else create a new object. This is inefficient and in reality doubles the workload and network usage compared to conditional $set.

      Sure, you can design around issues like this, but to minimize memory usage you want to commit calculations ASAP so you can free the used memory.

      And also, the above is possible with mapreduce, but if the aggregation is too complex for JS? Or you want to offload the server and do as much as possible of the calculations client-side?

      The ones I find useful is:

      • $setIfBigger ($gt)
      • $setIfSmaller ($lt)
      • $setIfAbsSmaller
      • $setIfAbsBigger

            Assignee:
            Unassigned
            Reporter:
            Fredrik Lindeberg
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: