2
我使用ODM蒙戈學說找到,我要記錄類主義的MongoDB通過ID
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")
}
我該如何查詢其他是給定ID的事情?
$dm=$this->mongo->getManager();
$answers=$dm
->createQueryBuilder('Bundle1:Thing')
->field('other')->equals("ObjectId(516c0061975a299edc44b419)") // <-- ?
->getQuery()
->execute()->count();
這將產生一個錯誤的蒙戈查詢
MongoDB的查詢: { 「發現」:真正的 「查詢」:{ 「其他」: 「的ObjectId(516c0061975a299edc44b419)」}, 「田」 :[], 「DB」: 「maself」, 「收藏」: 「東西」} [] []
當我使用
- >字段( '其他') - >等於( 「516c0061975a299edc44b419」)
查詢也有錯
MongoDB的查詢: { 「發現」:真正的 「查詢」:{ 「其它」: 「516c0061975a299edc44b419」}, 「田」:[], 「DB」: 「maself」, 「收藏」: 「東西」} [] []
所以,我怎麼能尋找的東西其他id等於objectId?