Consider the following code:
findAndModify({id: id}, undefined, {$inc: {counter: 1}, {$max: {counter: 10})
This fails with an error because both $inc
and $max
try to update the same field.
But what if I want to set the counter to 10 if its value is less than 10 and if not, increment its value by 1? How do I do that in one atomic operation?
Is there a way to apply the updates sequentially in a single operation?