title: What's the best way to update multiple values in an array of documents using MongoDB?
body: <p>So I have a document in the db, which looks like this:</p>
  <pre><code>...
  someArray: [{
  id: string
  qty: number
  }]
  ...
  </code></pre>
  <p>A db query needs to update this single document and increase the value of &quot;qty&quot; field for those entries in the array which match certain conditions.</p>
  <p>I know I can do this in many ways, with one (arrayFilters) or multiple queries etc. But I need to meet the following requirements:</p>
  <ul>
  <li><p>No other update operation must modify this document while my update is running. My understanding is that MongoDB 4.4 already guarantees this as long as I do this as a single operation (atomic updates). Is that correct?</p>
  </li>
  <li><p>Each matching value must be updated or none of them should be updated. So if I can only update 2 elements of the array and a 3rd one is not updated because the condition fails, I need to revert the whole operation.</p>
  </li>
  </ul>
  <p>What's the best way to do that?</p>
  <p>I mean, transactions are not useful here, since I'm updating only a single document.
  Also, if an update condition fails, that's not an error, so the transaction wouldn't revert.</p>
  <p>On the other hand, if I use multiple update operations to do this, then another update (started by another user) might modify the record and I couldn't revert.</p>
  <p>Is there a better way to do this?</p>
  <p>Thanks in advance!</p>