我是 mongodb 的新手,使用聚合函数来获取一些记录
我使用的查询是:
$records = $this->raw()->aggregate([
['$match' => ["ts" => ['$gte'=> $startTime,'$lt'=> $endTime]]],
['$group' => ["_id" =>["config" => '$conf', "status" => '$s' ], "count" =>['$sum' =>1]],
"ts" =>
[
'$dateToString' =>
[
'format' => '%Y-%m-%d',
'date' => $startTime,
'timezone' => '+05:30'
]
]
]
])->toArray();
它返回一个错误:管道阶段规范对象必须只包含一个字段。 请有人告诉我我的查询有什么问题。基本上我想在记录中存储日期。
$records = $this->raw()->aggregate([
[
'$match' => ["ts" => [
'$gte'=> $startTime,
'$lt'=> $endTime
]
]
],
[
'$group' => [
"_id" => [
"config" => '$conf',
"status" => '$s'
],
"count" => [
'$sum' =>1
]
],
"ts" => [
'$dateToString' =>
[
'format' => '%Y-%m-%d',
'date' => $startTime,
'timezone' => '+05:30'
]
]
]
])->toArray();