0

I am getting The 'cursor' option is required error from every mongoose aggregate of a particular nodeJS application. But In that same system other applications having mongoose aggregate working fine. What is the fix? BTW the same application is working fine in other system

Code

function getTestParams(testconductedid, mark) {
return new Promise(function (resolve, reject) {
    Mark.aggregate([
        {
            $match: {
                testconductedid: testconductedid,
            }
        },
        {
            $group: {
                _id: '$testconductedid',
                max: { $max: '$total' },
                avg: { $avg: '$total' },
                rank: { $sum: { '$cond': [{ '$lt': [mark, "$total"] }, 1, 0] } },
            }
        }
    ], function (err, results) {
        console.log(JSON.stringify(results));
        resolve(results);
    })
});

}

Error

code:9
codeName:"FailedToParse"
errmsg:"The 'cursor' option is required, except for aggregate with the explain argument"
message:"The 'cursor' option is required, except for aggregate with the explain argument"
name:"MongoError"
ok:0
stack:"MongoError: The 'cursor' option is required, except for aggregate with the explain argument\n    at Function.MongoError.create (d:\Ignus\ignuslearn\ignuslearnnode\node_modules\mongoose\node_modules\mongodb-core\lib\error.js:31:11)\n    at commandCallback (d:\Ignus\ignuslearn\ignuslearnnode\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\server.js:1187:66)\n    at Callbacks.emit (d:\Ignus\ignuslearn\ignuslearnnode\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\server.js:119:3)\n    at Connection.messageHandler (d:\Ignus\ignuslearn\ignuslearnnode\node_modules\mongoose\node_modules\mongodb-core\lib\topologies\server.js:358:23)\n    at Socket. (d:\Ignus\ignuslearn\ignuslearnnode\node_modules\mongoose\node_modules\mongodb-core\lib\connection\connection.js:292:22)\n    at emitOne (events.js:116:13)\n    at Socket.emit (events.js:211:7)\n    at addChunk (_stream_readable.js:263:12)\n    at readableAddChunk (_stream_readable.js:250:11)\n    at Socket.Readable.push (_stream_readable.js...
  • Update mongoose. MongoDB has changed the API for aggregate from MongoDB 3.6 and the underlying driver used by mongoose has to be updated in order for the call to be correct. Mongoose 5 and above implement the correct driver. The other option is go directly to the driver an issue the cursor option yourself and use it. But if you want the "toArray()" behavior you are used to with mongoose, it's probably far more simple to just update the version for your application. – Neil Lunn Apr 26 '18 at 21:18
  • @NeilLunn Can you please give the example for new `aggregation` of 3.6 version – Ashh Apr 30 '18 at 12:49
  • Update mongoose. You don't need to change anything else except to actually install the latest mongoose which is free of the bug – Neil Lunn Apr 30 '18 at 12:52

0 Answers0