[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


"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)

Could you please fix it?

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')
->near(36.5788494, -121.7207804)

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

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?


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(); 


Generated at Wed Nov 25 05:33:41 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.