我已经设置了一个类,如上所述 http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/reference/geospatial-queries.html
我的2d索引在mongo中正确设置
> db.system.indexes.find()
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "pfcd_dev.media", "name" : "_id_" }
{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "pfcd_dev.events", "name" : "_id_" }
{ "v" : 1, "key" : { "coordinates" : "2d" }, "ns" : "pfcd_dev.events", "name" : "coordinates_" }
当我在mongo shell上运行以下命令时,我得到了很多结果。
db.runCommand( { geoNear : "events" , near : [50,60], num : 10 } )
我已尝试near()
的所有以下变体,所有返回零结果
$places = $this->dm->createQueryBuilder('\Application\Event')->field('coordinates')->near('[50,60]')->getQuery()->execute();
$places = $this->dm->createQueryBuilder('\Application\Event')->field('coordinates')->near('50,60')->getQuery()->execute();
$places = $this->dm->createQueryBuilder('\Application\Event')->field('coordinates')->near(50,60)->getQuery()->execute();
$places = $this->dm->createQueryBuilder('\Application\Event')->field('coordinates')->near(array(50,60))->getQuery()->execute();
Doctrine网站上的文档似乎有点过时了。仅供记录,我已经创建了一个显示我的课程的要点(trucated)。 https://gist.github.com/1627491
这是debug()
$this->dm->createQueryBuilder('\Application\Event')->field('coordinates')->near('50,60')->debug();
Array
(
[type] => 10
[mapReduce] => Array
(
[map] =>
[reduce] =>
[options] => Array
(
)
)
[near] => Array
(
[coordinates] => 50,60
)
)
答案 0 :(得分:3)
您是否尝试过为您的模型摆脱extends Base
?
您也可以尝试以下方式:
$places = $this->dm->createQueryBuilder('\Application\Event')->field('coordinates.latitude')->near(50)->field('coordinates.longitude')->near(60)->getQuery()->execute();