1

Due to mongodb version change, i am getting "MongoError: The 'cursor' option is required, except for aggregate with the explain argument" error.

I've tried added cursor but still it is giving error.

QosAggregator.prototype.aggregatePingsByCheck = function(start, end, callback) {
  Ping.aggregate(
    { $match: { 
      timestamp: { $gte: start, $lte: end }
    } },
    { $project: {
      check: 1,
      responsive: { $cond: [ { $and: ["$isResponsive"] }, 1, 0] },
      time: 1,
      tags: 1,
    } },
    { $group: {
      _id: "$check",
      count: { $sum: 1 },
      responsiveness: { $avg: "$responsive" },
      responseTime: { $avg: "$time" },
      start: { $first: start.valueOf() }, // dunno any other way to set a constant
      end: { $first: end.valueOf() }
    } },
    callback
  ).cursor({});
};
Ashh
  • 44,693
  • 14
  • 105
  • 132
  • can you please tell me what's your mongodb version – Narendra Chouhan Apr 01 '19 at 09:24
  • 1
    You appear to be using an old release of Mongoose. Please update that to the latest version as well. Latest release MongoDB versions no have the option to return an `aggregate()` result as an `Array` like their used to be. Older mongoose versions relied on this `Array` and now they understand to use the cursor and convert afterwards. – Neil Lunn Apr 01 '19 at 09:28
  • @NarendraChouhan I am using version 3.6.7 as it is old code base project. – shailendra singh Apr 01 '19 at 10:44
  • @shailendrasingh so this is your mongodb version can you check the query in the robomongo, i think your project mongo version would be lower – Narendra Chouhan Apr 01 '19 at 10:47

0 Answers0