【发布时间】:2017-04-06 09:26:58
【问题描述】:
我想用他们拥有的产品对城市进行分类。
我有两个文件:产品和城市。产品有自己的 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()
;
}
【问题讨论】:
-
使用
group by city而不是distinct -
@aynber,对不起,我更改了实例名称以在这里提出问题 - 已修复。我还尝试了 mongodb 的组,但没有用。 :x
标签: php mongodb symfony doctrine-odm odm