Reputation: 2343
We are facing a very annoying issue with Mongoose.
The save
method takes around 500 / 600ms and it is very CPU consuming.
We have a sub-document with 50000 array elements which gets a new element (history) every each update using push.
Here is the code:
..... very large function
variable.value = parseFloat(value);
variable.history.push([{
value: parseFloat(value),
timestamp: dateNow
}]);
await variable.save();
..... end function
I have indexes on history and _id.
Any hint on why this is taking so long and consuming 60%...80% CPU ?
Thanks
Upvotes: 2
Views: 466
Reputation: 1758
I had a similar issue and looked all over and there doesn't seem to be a reasonable solution other than modifying your schema.
My save function would take very long after the document had a large sub-document array with over 100K entries.
I removed the array from the document and created a new schema, so instead of pushing to the sub-document array, I created a new one.
Upvotes: 1