我在Doctrine和MongoDB(ODM)中遇到问题。这是我的文档示例:
[
{
"id": "some_id",
"country": "Germany",
"cities": [{
"city": "Munich"
}, {
"city": "Berlin"
}, {
"city": "Hamburg"
}]
},
{
"id": "some_id",
"country": "Russia",
"cities": [{
"city": "Moscow"
}, {
"city": "Saint Petersburg"
}, {
"city": "Samara"
}]
},
{
"id": "some_id",
"country": "United Kingdom",
"cities": [{
"city": "London"
}, {
"city": "Birmingham"
}, {
"city": "Bristol"
}]
}
]
我想返回一个来自俄罗斯城市的数组,这是我当前的查询:
$query = $this->createQueryBuilder()
->select('cities')
->field('country')->equals('Russia')
->hydrate(false)
->getQuery()
->execute();
$result = iterator_to_array($query);
$result
返回每个国家/地区所有城市的数组,但我只获得俄罗斯的城市。
谢谢!