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