2

I have a problem with a query in Doctrine and MongoDB (ODM). This is my document example:

 [ 
  {
    "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"
    }]
   }

]

I want to return an array with cities from Russia, this is my current query:

$query = $this->createQueryBuilder()
            ->select('cities')
            ->field('country')->equals('Russia')
            ->hydrate(false)
            ->getQuery()
            ->execute();
        $result = iterator_to_array($query);

The $result return an array of all cities every country, but I get only the cities from Russia.

Thanks!

alvarezsh
  • 503
  • 3
  • 8
  • 21
  • Not sure if I get the problem as question is not stated, but `$result` should contain array(s) with key `cities` under which you'll find the cities. – malarzm Nov 05 '16 at 08:57

0 Answers0