我想用他們擁有的產品來對城市進行分類。如何在mongodb querybuilder中「按字段」「計數」分組?
我有兩個文件:產品和城市。該產品具有它的ID和一個城市的某一個文件:
Product(id) City
P1 ------------ Atlanta
P2 ------------ New York
P3 ------------ Michigan
P4 ------------ Atlanta
....
我想作爲查詢
[Atlant => 23, New York => 35, Michigan => 23, etc..]
但我不能夠得到的結果的結果。
我實際的代碼是
public function countBestUsers()
{
return $this->createQueryBuilder()
->select('id', 'city')
->distinct('city')
->getQuery()
->execute()
;
}
使用'城市組'而不是'distinct' – aynber
@aynber,對不起,我更改了實例名稱以問這裏的問題 - 修正。我也嘗試過爲MongoDB的組,但沒有工作。 :x –