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.
In this process CPU usage is 32% & disk usage is 100% I mentioned the basic code here by which you guys get some idea:
// I am using mongoose.
let filteredArray = [...]//contains 50000 entries
console.time()
let bulkOps = [];
filteredArray.map( (x) => {
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"})
Can someone have any idea why node.js not responding and return the response? Any help is really appreciated on that.
Another approach This approach takes 2 minute 10 seconds around to complete the task.
In this process CPU usage is 100% & disk usage is 100%
console.time()
await Promise.all(
filteredArray.map(async (x) => {
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"})
But here also not getting the API response.