Details
-
New Feature
-
Resolution: Duplicate
-
Major - P3
-
None
-
None
-
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" :
,
"$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