Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work-around for .find().sort() and QueryExceededMemoryLimitNoDiskUseAllowed #10177

Closed
bluepuma77 opened this issue Apr 26, 2021 · 2 comments
Closed
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@bluepuma77
Copy link

When using a .find().sort().exec() on a large table I get a QueryExceededMemoryLimitNoDiskUseAllowed exception:

MongoError: Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting.
    at MessageStream.messageHandler (/Users/server/node_modules/mongodb/lib/cmap/connection.js:268:20)
    at MessageStream.emit (node:events:369:20)
    at MessageStream.emit (node:domain:470:12)
    at processIncomingData (/Users/server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/Users/server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (node:internal/streams/writable:395:12)
    at MessageStream.Writable.write (node:internal/streams/writable:340:10)
    at Socket.ondata (node:internal/streams/readable:750:22)
    at Socket.emit (node:events:369:20)
    at Socket.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:313:12)
    at readableAddChunk (node:internal/streams/readable:288:9)
    at Socket.Readable.push (node:internal/streams/readable:227:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 7, high_: 1619430623 },
  ok: 0,
  code: 292,
  codeName: 'QueryExceededMemoryLimitNoDiskUseAllowed',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 7, high_: 1619430623 },
    signature: { hash: [Binary], keyId: [Long] }
  }
}

I read that for aggregations I can just use .allowDiskUse(true). Is this not available for .find().sort() ?

mongodb 4.4
node v15.14.0
mongoose 5.12.5

{
    "compilerOptions": {
        "module": "commonjs",
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "target": "es2017",
        "noImplicitAny": false,
        "moduleResolution": "node",
        "sourceMap": true,
        "types": ["jest", "supertest", "node"],
        "outDir": "dist",
        "baseUrl": ".",
        "paths": {
            "*": ["node_modules/*"]
        }
    },
    "include": ["src/**/*"]
}
@IslandRhythms IslandRhythms added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Apr 26, 2021
@IslandRhythms
Copy link
Collaborator

Can't say more without a repro script, did you use .allowDiskUsage(true) when you ran that operation?

@vkarpov15 vkarpov15 added this to the 5.12.8 milestone Apr 27, 2021
@vkarpov15
Copy link
Collaborator

vkarpov15 commented May 10, 2021

Right now the workaround is to use the setOptions() function:

await Test.find().sort({ name: 1 }).setOptions({ allowDiskUse: true }).exec();

We'll add a allowDiskUse method in v5.12.8. Keep in mind that using allowDiskUse with queries requires MongoDB server >= 4.4, won't work with MongoDB 4.2 or older.

@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue labels May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants