Memory spike when using `find()`
See original GitHub issueDo you want to request a feature or report a bug? Report a bug
What is the current behavior?
When I make a Model#find
call with an $or
operator, not only does the operation take ~5 minutes, it also takes up ~1 GB memory.
If the current behavior is a bug, please provide the steps to reproduce. My use-case:
const result = await Guild.find({
$or: [
{ premium: { $eq: true } },
{ prefix: { $ne: 'p!' } },
{ blacklistedChannels: { $exists: true, $ne: [], $type: 'array' } },
],
});
Reproduction repo: https://github.com/almeidx/mongoose-memory-leak-repro
When I run node index.js
on this repository:
Not sure if relevant but, here are my collection details:
- documents: 8360
- size: 38.71MB
What is the expected behavior? I expected it to not take ~5 minutes to process, but I can understand why it could take that long to process. What I really didn’t expect is the operation using ~1 GB of memory.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.
14.17.1
, 5.12.15
and 3.6.8
, respectively
(I’m not sure if by ‘MongoDB’ you meant the mongodb
npm module or the version of the database. I am using MongoDB Atlas version 4.4.6
, mongodb
npm module version 3.6.8
)
Issue Analytics
- State:
- Created 2 years ago
- Comments:12
Managed to shave off another 5% in 5f9d7ba by reducing unnecessary key creation. In the future, we’ll investigate wrapping
strictMode
in a getter to see if that gives us a little more.No worries, glad you found a workaround. We’re going to keep working to try to improve our memory usage going forward, so thanks for your patience and for reporting this issue.