For MongoDB I'm looking for atomic update that will increment field and if that increment will exceeds maximum given number it will stat that maximum number. Same behavior can be achieved with combination of $inc and $min operators but sadly not in one atomic update. Look at example below.
Example document
{
"_id": 1,
"i": 0
}
Queries
db.test.update({_id:1}, {$set:{"a":"foo"}, $inc:{i:1}}); db.test.update({_id:1}, {$min:{i:2}});
db.test.update({_id:1}, {$set:{"b":"bar"}, $inc:{i:1}}); db.test.update({_id:1}, {$min:{i:2}});
db.test.update({_id:1}, {$set:{"c":"baz"}, $inc:{i:1}}); db.test.update({_id:1}, {$min:{i:2}});
Result document
{
"_id": 1,
"i": 2,
"a": "foo",
"b": "bar",
"c": "baz"
}
Update
Thanks to Christian P answer I realized that I forgot to mention one more condition. I need document to be updated because I need update more fields than is shown in example. In fact I need increment ceiling (maximum) condition in update statement. I've updated my example to make this clear.