$manager = new Manager('mongodb://ip:sort');
$param = [
'aggregate' => 'collection名称',
'pipeline' => [
['$group' => [
'_id' => '$name',//分组字段
'interval_times' => [
'$sum' => '$interval_time' // 聚合查询字段 要加上$
]
]],
],
['$sort'=>[
'interval_times'=>-1
]]
'cursor' => ['batchSize' => 0] //高版本mongodb必须要加cursor字段
];
$cmd = new Command($param);
$cursor = $manager->executeCommand('数据库名称', $cmd);
// 循环打印
foreach ($cursor as $item) {
dump($item);
}
php7 mongodb 分组 排序 查询
最新推荐文章于 2023-05-04 17:11:23 发布