balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

sum() with mongo adapter #4557

Open wizmea opened 5 years ago

wizmea commented 5 years ago

Sails version: 1.1.0 Node version:v10.5.0 NPM version:6.1.0 DB adapter name: sails-mongo DB adapter version: 1.0.1 Operating system: MacOS


and finally...

I have problem with sum() using waterline with mongo adapter

Query const amount = await RdvConsultation.sum('cost').where({ f_etablishment: data.id, payStatus: "PAID", createdAt: {'>=': firstDay, '<=': lastDay} })

Error { AdapterError: Unexpected error from database adapter: Internal error occurred while running sumRecords. Got non-Error: { MongoError: The 'cursor' option is required, except for aggregate with the explain argument at Function.MongoError.create (/Users/arcadius/taf/web/opensi/gomedical/gomedical-backend/node_modules/sails-mongo/node_modules/mongodb-core/lib/error.js:31:11) at /Users/arcadius/taf/web/opensi/gomedical/gomedical-backend/node_modules/sails-mongo/node_modules/mongodb-core/lib/connection/pool.js:489:72 at authenticateStragglers (/Users/arcadius/taf/web/opensi/gomedical/gomedical-backend/node_modules/sails-mongo/node_modules/mongodb-core/lib/connection/pool.js:435:16) at Connection.messageHandler (/Users/arcadius/taf/web/opensi/gomedical/gomedical-backend/node_modules/sails-mongo/node_modules/mongodb-core/lib/connection/pool.js:469:5) at Socket. (/Users/arcadius/taf/web/opensi/gomedical/gomedical-backend/node_modules/sails-mongo/node_modules/mongodb-core/lib/connection/connection.js:321:22) at Socket.emit (events.js:182:13) at Socket.EventEmitter.emit (domain.js:442:20) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10) at TCP.onread (net.js:635:20) 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 "sumRecords", 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.

sailsbot commented 5 years ago

Hi @wizmea! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

wizmea commented 5 years ago

Ok, fixed!

sailsbot commented 5 years ago

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact inquiries@sailsjs.com

wizmea commented 5 years ago

Ok, fixed!

sailsbot commented 5 years ago

@wizmea Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

raqem commented 5 years ago

Hi @wizmea sorry for the late reply. Were you able to resolve this issue? I was looking into your issue and compared it to the official docs It looks like there may be a chance that your formatting of your .where criteria needs to be changed a bit.

duzun commented 5 years ago

@wizmea what version of MongoDB are you running?

sails-mongo@1.0.1 depends on mongodb@2.2.25, which is compatible with MongoDB up to v3.4 only (the latest being v4.0).

See MongoDB Compatibility for reference.

Tarrask commented 5 years ago

This issue is fixed in sails-mongo: https://github.com/balderdashy/sails-mongo/commit/42f62c37fa767ae0ac91a97d4edc9b2e1e57b910

But the modification is still not published on npm, we need to wait for sails-mongo@1.0.2

johnabrams7 commented 5 years ago

@Tarrask - Thanks for the follow-up, I'll consult with the team on getting sails-mongo updated on npm.