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

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

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Write Ops
    • None
    • All applicable

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: