我在MongoDB中使用PHP聚合来获取日期范围的数据。我试图实现的结果应该是这样的日期范围:ISODate(“2016-05-24T15:08:32Z”)到ISODate(“2016-05-24T15:08:32Z”)
["year" => 2016
"month" => 6
"scoring" =>238
"count" => 96],
["year" => 2016
"month" => 65
"scoring" =>238
"count" => 96]
代码如下:
$pipeline =
[
['$match'=>[
'testId' => $id,
'date' => [
'$gte'=> $start(),
'$lte' =>$end()
],
]
],
['$group' => [
'_id' => [false],
'scoring' => ['$sum' => '$scoring'],
'count' => ['$sum' => 1],
],
]
];
我已经使用$ project来打破月份和年份,但我很难在日期范围内做到这一点而不是特定日期。 如果可能的话,有什么想法吗?