[SERVER-8448] No results with $near and $nearSphere queries using 2dsphere indexes and $maxDistance parameter Created: 04/Feb/13  Updated: 15/Feb/13  Resolved: 07/Feb/13

Status: Closed
Project: Core Server
Component/s: Geo, Querying
Affects Version/s: 2.3.2, 2.4.0-rc0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jim Dagg Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7 Professional


Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

1) Generate documents with 2dsphere index, including Point, LineString, and Polygon
2) Perform query using $near without $maxDistance – should return documents
3) Perform query using $near with $maxDistance – returns nothing

Participants:

 Description   

Per the current documentation for 2dsphere indexes, queries using $near and $nearSphere require a GeoJSON point passed to them, but otherwise work normally. However, $near and $nearSphere queries against a field with a 2dsphere index return no results if a $maxDistance parameter is provided.

e.g.
db.random.find( {geometry: { $nearSphere:

{type:"Point", "coordinates":[-83,40]}

}})
returns results, but

db.random.find( {geometry: { $nearSphere:

{type:"Point", "coordinates":[-83,40]}

, $maxDistance: 10}})
does not.



 Comments   
Comment by Jim Dagg [ 05/Feb/13 ]

Via communication with Hari Khalsa on the user forum (https://groups.google.com/forum/?fromgroups=#!topic/mongodb-user/5SecGQnDgUY), I learned that the $maxDistance parameter expects distances in meters, not in radians, when a GeoJSON point is provided to $nearSphere. So this appears to be working as designed.

Generated at Thu Feb 08 03:17:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.