2017-05-06 60 views
0

如果我寫匹配和組,就沒有工作。如果我刪除組或與之相匹配的正常工作如何在聚合MongoDB中進行匹配組?

$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

我解決了它,當我把比賽組之前,和它的作品對我的作品。

$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 
       ) 
      ) 
      ); 
相關問題