title: Cosmos DB - create document only if count < CONST
body: <p>I have a web application where customers create records.
  These records are saved in Cosmos DB.
  Each record is saved as a separate document.
  The partitioning key of the database is customer ID.</p>
  <p>I want to limit the number of records each customer can save to CONST.
  Therefore, I want to perform the following atomic operation in Cosmos DB:</p>
  <ul>
  <li>get number of documents where customerID is X</li>
  <li>Only if number of documents &lt; CONST, create new document.</li>
  </ul>
  <p>I want this operation to be atomic so there won't be a situation where the customer has more than CONST documents in the database.</p>
  <p>If I separate this to 2 distinct calls to cosmos DB, then there can be a situation where 2 instances query the dB for the same customer,see that number of documents is (CONST - 1) and therefore they both add a document.</p>
  <p>Is it possible to do this operation atomically? How?</p>
  <p>I tried to look into stored procedures but I'm not sure if this is the correct direction. Will it be possible to achieve this using it?</p>