【发布时间】:2016-02-08 05:51:31
【问题描述】:
我正在使用 odm mongo 原则,我必须记录类
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")
}
我现在如何查询 other 是给定 id 的东西?
$dm=$this->mongo->getManager();
$answers=$dm
->createQueryBuilder('Bundle1:Thing')
->field('other')->equals("ObjectId(516c0061975a299edc44b419)") // <-- ?
->getQuery()
->execute()->count();
这会产生错误的 mongo 查询
MongoDB 查询: {"find":true,"query":{"other":"ObjectId(516c0061975a299edc44b419)"},"fields":[],"db":"maself","collection":"thing"} [] []
当我使用时
->field('other')->equals("516c0061975a299edc44b419")
查询也是错误的
MongoDB 查询: {"find":true,"query":{"other":"516c0061975a299edc44b419"},"fields":[],"db":"maself","collection":"thing"} [] []
那么我如何搜索其他 id 等于 objectId 的东西?
【问题讨论】:
标签: php mongodb symfony doctrine-orm