[SERVER-2342] $within: {$center} vs. $near and $maxDistance Created: 10/Jan/11  Updated: 12/Jul/16  Resolved: 27/Jan/11

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 1.7.4
Fix Version/s: 1.7.6

Type: Bug Priority: Major - P3
Reporter: Kyle Banker Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File geo.dump    
Issue Links:
Duplicate
is duplicated by SERVER-2234 Sometimes geospatial requests do not ... Closed
Related
is related to SERVER-2341 Geospacial calculations are off Closed
Operating System: ALL
Participants:

 Description   

Shouldn't these two types of queries return the same results? They don't always. Why not?

Attached is a zip code database you can use to test.

Here are two queries:

> use geo
> db.zips.find({'loc': {$near:

{x: 40.752315, y: -73.977842}

, $maxDistance: 0.01}}).count()
3

> db.zips.find({loc: {$within: {$center: [ [40.752315, -73.977842], 0.01 ] }}}).count()
25

But...

> db.zips.find({'loc': {$near:

{x: 40.752315, y: -73.977842}

, $maxDistance: 0.011 }}).count()
26

> db.zips.find({loc: {$within: {$center: [ [40.752315, -73.977842], 0.011 ] }}}).count()
26

If they're supposed to return the same results, why have them both? If they're not, what's sort of meaningful distinction is there between them?



 Comments   
Comment by auto [ 27/Jan/11 ]

Author:

{u'login': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: fix $near with $maxDistance SERVER-2342
https://github.com/mongodb/mongo/commit/669b2f2dd36b11e17ae4ab21c2fdfec958ac72b9

Comment by Scott Hernandez (Inactive) [ 10/Jan/11 ]

Isn't the difference here whether the $maxDistance value is inclusive or exclusive? In the $near case it is not, and for $whithin it is.

This is how I understood things to work.

Is there something more going on?

Comment by Mathias Stearn [ 10/Jan/11 ]

I think these are related. The handling of $maxDistance is off.

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