所以我试图让我的数据按月细分,并遵循我在一些 SO 帖子中看到的模式,但是 _id 结果返回为空,我似乎无法理解为什么。我的模型中的日期确实是 Date 类型。
{
$match: {
date: {$gte: startDate, $lte: endDate }
},
$project: {
'date': 1
, 'fatigue.percent': 1
, 'fitness.percent': 1
, 'maintenance.percent': 1
, 'substances.percent': 1
, 'unsafe.percent': 1
, 'created_on': {
month: { '$month': '$date' }
}
}
,$group: {
_id: '$created_on'
, averageFatigue: {$avg : '$fatigue.percent'}
, averageFitness: {$avg : '$fitness.percent'}
, averageMaintenance: {$avg : '$maintenance.percent'}
, averageSubstances: {$avg : '$substances.percent'}
, averageUnsafe: {$avg : '$unsafe.percent'}
}
}