Subdoc decrement operation restrict numeric values beyond zero?


We implemented counter operations with using subdoc mutatein functions. But decrementing goes under zero. In the documentation, if we use decrement function (not subdoc), decrementing operation will be restricted zero(not negative values.). But we’d like to use subdoc decrementing operation and do not want field to go under zero.

Is there a way to do that without doing manually?


Hi @erkan.erkisi unfortunately I don’t think that we have a way to prevent subdoc decrement from reducing a value below zero. I’m also struggling to think of a way to do what you want without having to do a fetch first which could get a bit racey.

Thanks charles, I guess we need to fetch first and then check the number is below zero and update if not.