Let's say I have the document city
and the document country
.
city
' references to country
by country: ObjectId("xxxx")
How can I find cities by countries' field, eg. db.Cities.find({"country.code":"US"}
Is it possible? I think not, but might it be possible using MongoDB ORM for PHP?
I tried
$qb = $this->database->createQueryBuilder(self::NAMESPACE_CITY);
$qb->field('country.code')->equals("US")`
My City
entity contains
/** @ODM\ReferenceOne(targetDocument="\Doctrine\Documents\Country", simple=true) */
protected $country;
Document example:
<?php
namespace Doctrine\Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Application\Doctrine\Documents\Document;
/** @ODM\Document(collection="Cities") */
class City extends Document {
/** @ODM\Id */
protected $_id;
/** @ODM\ReferenceOne(targetDocument="\Doctrine\Documents\Country", simple=true) */
protected $country;
}