I'm using odm mongo doctrine and I have to document-classes
class Thing
{
/**
* @MongoDB\Id
*/
protected $id;
/**
* @MongoDB\ReferenceOne(targetDocument="Bundle1:Other")
*/
protected $other;
}
class Other
{
/**
* @MongoDB\Id
*/
protected $id;
}
{
"_id":ObjectId("43z758634875adf"),
"other":ObjectId("38z287348d8se")
}
$dm=$this->mongo->getManager();
$answers=$dm
->createQueryBuilder('Bundle1:Thing')
->field('other')->equals("ObjectId(516c0061975a299edc44b419)") // <-- ?
->getQuery()
->execute()->count();
MongoDB query:
{"find":true,"query":{"other":"ObjectId(516c0061975a299edc44b419)"},"fields":[],"db":"maself","collection":"thing"}
[] []
->field('other')->equals("516c0061975a299edc44b419")
MongoDB query:
{"find":true,"query":{"other":"516c0061975a299edc44b419"},"fields":[],"db":"maself","collection":"thing"}
[] []
Try
->field('other')->equals(new \MongoId("516c0061975a299edc44b419"))
ObjectId is the internal type for Mongo, represented by \MongoId() in PHP
( But i have also answered in the first topic )