Doctrine MongoDB znajdź według id
Używam doktryny odm mongo i muszę klasować dokumenty
class Thing
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\ReferenceOne(targetDocument="Bundle1:Other")
*/
protected $other;
}
i
class Other
{
/**
* @MongoDB\Id
*/
protected $id;
}
więc w bazie danych wygląda:
{
"_id":ObjectId("43z758634875adf"),
"other":ObjectId("38z287348d8se")
}
Jak mogę teraz zapytać o rzeczy, dla których inne są identyfikatorami?
$dm=$this->mongo->getManager();
$answers=$dm
->createQueryBuilder('Bundle1:Thing')
->field('other')->equals("ObjectId(516c0061975a299edc44b419)") // <-- ?
->getQuery()
->execute()->count();
Spowoduje to powstanie błędnego zapytania mongo
Zapytanie MongoDB: {"find": true, "query": {"other": "ObjectId (516c0061975a299edc44b419)"}, "fields": [], "db": "maself", "collection": "thing"} [] []
Kiedy używam
-> pole („inne”) -> równe („516c0061975a299edc44b419”)
zapytanie jest również błędne
Kwerenda MongoDB: {"find": true, "query": {"other": "516c0061975a299edc44b419"}, "fields": [], "db": "maself", "collection": "thing"} [] [ ]
Jak więc szukać rzeczy, w których inny identyfikator jest równy obiektowi?