balderdashy / balderdashy/sails
MongoError: The 'cursor' option is required, except for aggregate with the explain argument
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**DB adapter & version** : _sails-mongo@1.0.1_
Getting issue while calculating the ave on a document filed.
As mongo 3.5 onward we need to provide *cursor* option also along with criteria.
Please update the sails mongo to accommodate this change or let me know I'll create a PR.
Thanks
Full Stack
```
info: Custom response `res.serverError()` called with an Error: { AdapterError: Unexpected error from database adapter: Internal error occurred while running `avgRecords`. Got non-Error: { MongoError: The 'cursor' option is required, except for aggregate with the explain argument
at Function.MongoError.create (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:489:72
at authenticateStragglers (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:435:16)
at Connection.messageHandler (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:469:5)
at Socket. (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/connection.js:321:22)
at Socket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)
name: 'MongoError',
message:
"The 'cursor' option is required, except for aggregate with the explain argument",
ok: 0,
errmsg:
"The 'cursor' option is required, except for aggregate with the explain argument",
code: 9,
codeName: 'FailedToParse' }
If you are the maintainer of "avgRecords", then you can change its implementation to solve the problem (Most of the time, the solution is just to throw an actual Error instance instead. Alternatively, if the goal was to indicate a particular exception, you could throw any of the special, reserved "exit signals"-- e.g. the code name of any of your defined exits besides "error" or "success"). Otherwise, please file a bug report with the maintainer, or fork your own copy and fix that.
[?] See https://sailsjs.com/support for help.
at Function.MongoError.create (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:489:72
at authenticateStragglers (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:435:16)
at Connection.messageHandler (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:469:5)
at Socket. (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/connection.js:321:22)
at Socket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)
at newConstructor.recalculateRating (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/api/models/Review.js:141:36)
From previous event:
at Deferred.toPromise (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/parley/lib/private/Deferred.js:572:19)
at Deferred.then (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/parley/lib/private/Deferred.js:431:22)
at processTicksAndRejections (internal/process/next_tick.js:81:5)
cause:
{ AdapterError: Unexpected error from database adapter: Internal error occurred while running `avgRecords`. Got non-Error: { MongoError: The 'cursor' option is required, except for aggregate with the explain argument
at Function.MongoError.create (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:489:72
at authenticateStragglers (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:435:16)
at Connection.messageHandler (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/pool.js:469:5)
at Socket. (/Users/vishnumishra/Documents/projects/freeeup/timeclock/sails/node_modules/mongodb-core/lib/connection/connection.js:321:22)
at Socket.emit (events.js:197:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:145:17)
name: 'MongoError',
message:
"The 'cursor' option is required, except for aggregate with the explain argument",
ok: 0,
errmsg:
"The 'cursor' option is required, except for aggregate with the explain argument",
code: 9,
codeName: 'FailedToParse' }
```
Contributor guide
Research direction
Start with the avgRecords call shown in api/models/Review.js at line 141 and trace how the sails-mongo adapter handles the aggregate criteria. Verify the behavior against MongoDB 3.5 or newer, then run the relevant adapter checks. Done means average queries no longer fail with the missing cursor error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100