title: MongoDB decrement until zero
body: <p>I would like to achieve an operation in MongoDB that would be analogous to <code>doc.value = max(doc.value - amount, 0)</code>. I could do it by fetching document, updating its value then saving it, but is it possible with an atomic operation to avoid problems with synchronisation of parallel decrements?</p>