php7 mongodb 分组 排序 查询

$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);
        }

你可能感兴趣的:(数据库技术)