我有 2 个系列,类别和产品。每个产品都有一个 category_id。我想列出产品数量的类别名称......我已经用 1 个循环和 2 个查询完成了这个。但我想把它作为一个单一的查询。如何在 mongo DB 中生成它?
public function GetCategories(){
$data = array();
$this->cimongo->where(array('status'=>'1'));
$query = $this->cimongo->get('category');
foreach($query->result_array() as $category){
$data[] = array(
'keyword' => $category['keyword'],
'name' => $category['name'],
'total' => $this->GetTotalWordsByCategoryId($category['_id'])
);
}
return $data;
}