[MODM-153] "Near" Query does not work. Created: 10/Aug/11  Updated: 20/Feb/12

Status: Open
Project: Doctrine MongoDB ODM
Component/s: None
Affects Version/s: 1.0.0BETA2
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: Dmitry Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 0
Labels: None


 Description   

"Near" statement does not work for me. The following code returns all cities from collection:

$cities = $this->dm->createQuery('City')
    ->field('coordinates')->near(50, 60)
    ->execute();

Could you please fix it?



 Comments   
Comment by mark wright [ 02/Sep/11 ]

It also does not work in beta3 but it fails differently. It never returns anything.

$places = $documentManager->createQueryBuilder('Documents\Place')
->field('point')
->near(36.5788494, -121.7207804)
->getQuery()
->execute();

This returns 0 documents even though I have a point at 36.5788493, -121.7207805. Doctrine\MongoDB\Query\Builder::near() only takes one argument so the Y value is ignored. However, the docblock specifies 2 params.

Comment by Tim Sakharchuk [ 04/Sep/11 ]

Hi All,

Here is correct realization of this function in
Doctrine\MongoDB\Query\Builder

public function near($x, $y)

{ $this->query['type'] = Query::TYPE_GEO_LOCATION; $this->query['near'] = array($x, $y); return $this; }

When may this fix appear in Doctrine ODM?

Thanks!

Comment by Shane A. Stillwell [ 20/Feb/12 ]

I had the same issue on 1.0.0.BETA3.

The solution was to change the query up a little.

$places = $this->dm->createQueryBuilder('\Application\Event')->field('latitude')->near(50)->field('longitude')->near(60)->getQuery()->execute(); 

http://stackoverflow.com/a/9015906/179335

Generated at Sun Nov 23 16:21:10 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.