Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.3
    • Component/s: Write Ops
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible

      Description

      Add $min/max update modifiers which leave/replace the existing field based on the comparison of a provided value.

      Note: if the field is missing then the value supplied will replace it like it was specified via a $set.

      Examples:

      > db.v.find()
      {_id:1, v:1}
      {_id:2, v:2}
      {_id:3}
      {_id:4}
      > db.v.update({_id:1}, {$min: {v: 2}} // do not change the doc, existing value is smaller
      > db.v.update({_id:1}, {$min: {v: 0}} // set v to 0
      > db.v.findOne({_id:1})
      {_id:1, v:0}
       
      > db.v.update({_id:2}, {$max: {v: 1}} // do not change the doc, existing value is larger
      > db.v.update({_id:2}, {$max: {v: 2}} // do not change the doc, existing value is the same
      > db.v.update({_id:2}, {$max: {v: 200}} // set v to 200
      > db.v.findOne({_id:2})
      {_id:2, v:200}
       
      > db.v.update({_id:3}, {$min: {v: 2}} // set v to 2
      {_id:3, v:2}
      > db.v.update({_id:4}, {$max: {v: 2}} // set v to 2
      {_id:4, v:2}
      

      old description
      I'm working on a realtime website performance analysis tool, were a number of parallel processes import data into a mongodb instance.

      In this context, it would be extremely helpful to have $max and $min update operators which would work similar to $inc.

      { $min :

      { field : value }

      }

      sets field to new value if field does not exist or value is smaller than current field value.

      { $max :

      { field : value }

      }

      sets field to new value if field does not exist or value is larger than current field value.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                38 Vote for this issue
                Watchers:
                33 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: