我收到“ MongoError:“ cursor”选项是必需的,但带有解释参数的聚合除外”错误

时间:2019-04-01 09:21:36

标签: node.js mongodb mongoose

由于mongodb版本的更改,我收到“ MongoError:需要'cursor'选项,但带有说明参数的聚合除外”。

我尝试添加游标,但仍然显示错误。

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({});
};

0 个答案:

没有答案