如果我写匹配和组,就没有用。如果我删除了组或匹配它可以正常工作
$collection = Yii::$app->mongodb->getCollection('products');
$result = $collection->aggregate(array(
array(
'$group' => array(
'_id' => array('city_id' => '$city_id'),
'count' => array( '$sum' => 1)
),
),
array(
'$match' => array('user_id' => $filter['user_id']),
),
array(
'$limit' => 20
)
)
);
答案 0 :(得分:0)
我解决了它,当我在小组之前放置比赛并且它对我有效时它起作用。
$collection = Yii::$app->mongodb->getCollection('products');
$result = $collection->aggregate(array(
array(
'$match' => array('user_id' => $filter['user_id']),
),
array(
'$group' => array(
'_id' => array('city_id' => '$city_id'),
'count' => array( '$sum' => 1)
),
),
array(
'$limit' => 20
)
)
);