[SERVER-1191] $within:$center returns documents outside of the given circle Created: 03/Jun/10  Updated: 12/Jul/16  Resolved: 30/Jun/10

Status: Closed
Project: Core Server
Component/s: Geo
Affects Version/s: 1.5.2
Fix Version/s: 1.5.4

Type: Bug Priority: Major - P3
Reporter: Tomas Carnecky Assignee: Richard Kreuter (Inactive)
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

The first command returns a document which is outside of the given circle. Decreasing the radius doesn't help.
> db.aggregates.find({position:{$within:{$center:[[46.16760025, 8.79330351666667],0.00001]}}})

{ "_id" : ObjectId("4c07ca39f18d653fb9000001"), "position" : [ 46.16997015, 8.799318833333333 ] }

The geoNear command returns the same object but calculates a distance which is higher than the radius used in the above command.
> db.runCommand(

{ geoNear : "aggregates" , near : [46.16760025, 8.79330351666667], num : 1 }

);
{
"ns" : "myway.aggregates",
"near" : "1100100000010100101100100010000011010000101110010100",
"results" : [
{
"dis" : 0.0064640792077458676,
"obj" :

{ "_id" : ObjectId("4c07ca39f18d653fb9000001"), "position" : [ 46.16997015, 8.799318833333333 ] }

}
],
"stats" :

{ "time" : 0, "btreelocs" : 0, "nscanned" : 1, "objectsLoaded" : 1, "avgDistance" : 0.0064640792077458676 }

,
"ok" : 1
}
>



 Comments   
Comment by Richard Kreuter (Inactive) [ 30/Jun/10 ]

By inspection, this bug went away in commit 93661510e975f9c8a62f315c6a602fecbf50cbfb.

Comment by auto [ 08/Jun/10 ]

Author:

{'login': 'kreuter', 'name': 'Richard Kreuter', 'email': 'richard@10gen.com'}

Message: Add an error term for distance comparisons in geo search. Part of SERVER-848, SERVER-1191
http://github.com/mongodb/mongo/commit/93661510e975f9c8a62f315c6a602fecbf50cbfb

Comment by Eliot Horowitz (Inactive) [ 03/Jun/10 ]

its for floating point rounding errors

it needs to scale intelligently though will change

Comment by Tomas Carnecky [ 03/Jun/10 ]

While looking through the source I found this: (http://github.com/mongodb/mongo/blob/master/db/index_geo2d.cpp#L1347)

virtual bool checkDistance( const GeoHash& h , double& d ){
d = _g->distance( _start , h );
GEODEBUG( "\t " << h << "\t" << d );
return d <= ( _maxDistance + .01 );
}

Why is there the +.01? If I replace it with .000001 the query from the description no longer returns the document (which is the correct behavior).

Generated at Thu Feb 08 02:56:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.