php :: Aggregation :: $ avg ::结果未定义在:: mongodb中?

时间:2017-04-29 00:34:12

标签: php mongodb aggregation-framework

这是函数聚合

$query =$et->aggregate(
[
    [ '$match' => [ 'operasi' => '"INSERT"' ] ],
    [ '$group' => [
            '_id' => '$record',
            'avg' => [ '$avg' => '$extime' ]
    ] ],

    ['$sort' => ["_id" => 1]]
]);`

此语法显示结果

 $rows1 = array();
$rows1['name'] = 'Mongodb';
foreach ($query as $row) {
echo $rows1['data'][]=$row['avg'];
}

然后执行:

Notice: Undefined index: avg in E:\xampp\htdocs\RISET\result\insert.php on line 40

var_dump($query);

的结果
array(3) { ["waitedMS"]=> int(0) ["result"]=> array(3) { [0]=> array(2) { ["_id"]=> string(2) "10" ["avg"]=> float(0.26921399434408) } [1]=> array(2) { ["_id"]=> string(3) "100" ["avg"]=> float(0.7808530330658) } [2]=> array(2) { ["_id"]=> string(6) "100000" ["avg"]=> float(85.200194120407) } } ["ok"]=> float(1) }

我该怎么办?

0 个答案:

没有答案