title: MongoDB Bulkwrite query freezes the Node.js Response
body: <p>I was testing the bulk update on MongoDB through node.js API. For updating 50000 entries, it takes around 8 minutes 30 seconds and then MongoDB finishes its job but not getting the API response from Node.js API.</p>
  
  <p>In this process CPU usage is 32% &amp; disk usage is 100%
  I mentioned the basic code here by which you guys get some idea:</p>
  
  <pre><code>// I am using mongoose.
  let filteredArray = [...]//contains 50000 entries
  console.time()
  
  
  let bulkOps = [];
  filteredArray.map( (x) =&gt; {
      let upsertDoc = {
          'updateOne': {
              'filter': { keywords: x.keywords },
              'update': {
                  $inc: { counter: -1 },
                  $pull: {
                      data: {
                          dataid: req.body.dataid
                      },
                  },
              },
              'upsert': true
          }
      }
  bulkOps.push(upsertDoc);
  });
  await TestDataTable.bulkWrite(bulkOps);
  console.timeEnd()
  return res.send({status: 200, message: "Enteries updated successfully"})
  </code></pre>
  
  <p>Can someone have any idea why node.js not responding and return the response? Any help is really appreciated on that.</p>
  
  <p><strong>Another approach</strong>
  This approach takes 2 minute 10 seconds around to complete the task.</p>
  
  <p>In this process CPU usage is 100% &amp; disk usage is 100%</p>
  
  <pre><code>console.time()
                      await Promise.all(
                          filteredArray.map(async (x) =&gt; {
                              await TestDataTable.updateOne(
                                  { keywords: x.keywords },
                                  {
                                      $inc: { counter: -1 },
                                      $pull: {
                                         data: {
                                            dataid: req.body.dataid
                                         },
                                      },
                                  },
                              ).exec();
                          }),
                      );
                      console.timeEnd()
  return res.send({status: 200, message: "Enteries updated successfully"})
  
  </code></pre>
  
  <p>But here also not getting the API response.</p>