Mongo Doctrine查询生成器选择不起作用。错误?

时间:2012-10-22 15:22:07

标签: php mongodb doctrine doctrine-orm

$dm = $this->get('doctrine.odm.mongodb.document_manager');

$query = $dm->createQueryBuilder('MyBundle:Listing')
            ->select('title')
            ->field('coordinates')->geoNear(
                  (float)$longitude, 
                  (float)$latitude
            )->spherical(true);

$classifieds_array = $classifieds->toArray();

$data = array('success'=>true,'classifieds' => $classifieds_array, 
      'displaymessage' => $classifieds->count(). " Search Results Found");

即使我只选择一个字段,但对于我的结果集,我会将所有内容与标题一起收回。这是一个错误吗?

注意:我注释掉->field('coordinates')->geoNear((float)$longitude, (float)$latitude)->spherical(true)行,现在选择似乎有效。这太疯狂了。

1 个答案:

答案 0 :(得分:0)

根据文档示例,MongoDB中的geoNear命令似乎不支持过滤结果字段。仅支持query选项来限制匹配的文档。

在您的情况下,它似乎也混合了Doctrine中的geoNear()near()构建器方法。由于您在coordinates字段上操作,因此相应的语法为near()geoNear()是告诉构建器您希望使用该命令的顶级方法,该命令不需要字段名称,因为它使用集合上唯一的地理空间索引。

对于用法示例,我建议查看Doctrine MongoDB库中的query and builder unit tests

相关问题