title: Node js concurrent requests
body: <p>I am using a NodeJs server with Mongo Db and i have the following controller, which does the following:
  (this is a simplified version of the code but it displays the main problem)</p>
  
  <pre><code>const activeTransactions = await Transactions.find({userId,status:"pending"})
  if (activegpChatRequests.length &gt; 0) {
     return some error here
  }
  const transaction = await Transaction.create({userId})
  return transaction
  </code></pre>
  
  <p>Now this controller works fine. However there is a problem when sending 2 requests at the same time. What happens is that the second request evaluates the activeTransactions line before the the transaction is created by the first request. So the end result is that 2 transactions are created. (when the intended behaviour should be creating a transaction for request 1 then sending an error for request 2)</p>