我有一个汇总查询,该查询汇总过去7天内的总未解决警报。我的查询有效-在最近两天内检索计数。但是,对于没有可用数据的日期,它不会返回0计数。我如何也将它们包括在内?
我当前的查询:
alerts.aggregate([{
$match: {
"misc.createdTime": {
$gt: new Date(weekStart) // 7 days ago
},
alertState: alertState,
alertCategory: {'$regex': alertCategory}
}
},
{
$group: {
_id: {
$dateToString: {
format: "%Y%m%d",
date: "$misc.createdTime"
}
},
count: { $sum: { $cond: [ { $eq: [ "$match", "none" ] }, 0, 1 ] } } // => based on another SO answer, but doesn't seem to work.
// count: {
// $sum: 1
// }
}
},
{
$sort: {
_id: 1
}
}
]).toArray();