title: Make incoming requests execute serially in NodeJS(express)
body: <p>I am currently working on a token booking system for a hospital and am using MongoDB atlas as the database. Due to the network latency, concurrent requests are causing some trouble. So I am trying to make the requests execute serially to avoid any booking being saved with the same time slot. </p>
  
  <p>This is my requirement:</p>
  
  <p>Say, my incoming request body is of the form:</p>
  
  <pre><code>{
    ...
    "depatmentID":"dept1",
    ...
  }
  </code></pre>
  
  <p>Basically what happens when a request comes is given below:</p>
  
  <pre><code>DepartmentDetails.findOne({department: departmentID}).then((department) =&gt; {
      /* 
      1. fetch department details
      2. update some of the fields like : 
         incrementing total number of tokens booked, last token time slot etc..
  
      (there are some other computations as well)
  
      3. now update the details in MongoDB
      */
      DepartmentDetails.findOneAndUpdate({department: departmentID}, dataToUpdate).then((data) =&gt; {
          //4. send response
      })
  })
  </code></pre>
  
  <p><strong>For all the (concurrent) requests having same <code>departmentID</code>, I need to execute the route function serially</strong>. I have tried various methods and nothing worked.</p>
  
  <p>Please do help me with this.</p>
  
  <p>Thanks in advance.</p>