-
Type: Task
-
Resolution: Won't Fix
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: manual
-
Labels:
-
Environment:Mongo v2.4.4 hosted by MongoLab
*Location*: http://docs.mongodb.org/manual/reference/operator/near/
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1
*Referrer*: http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC4QFjAA&url=http%3A%2F%2Fdocs.mongodb.org%2Fmanual%2Freference%2Foperator%2Fnear&ei=1lMSUvSsDoqMyQHlhYAw&usg=AFQjCNE0k4sAyfIWH48iWxL8Ci03R2gsKg&bvm=bv.50768961,d.aWc
*Screen Resolution*: 1280 x 800
*repo*: docs
*source*: reference/operator/near
Mongo v2.4.4 hosted by MongoLab *Location*: http://docs.mongodb.org/manual/reference/operator/near/ *User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1 *Referrer*: http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC4QFjAA&url=http%3A%2F%2Fdocs.mongodb.org%2Fmanual%2Freference%2Foperator%2Fnear&ei=1lMSUvSsDoqMyQHlhYAw&usg=AFQjCNE0k4sAyfIWH48iWxL8Ci03R2gsKg&bvm=bv.50768961,d.aWc *Screen Resolution*: 1280 x 800 *repo*: docs *source*: reference/operator/near
Hi,
I've been doing some testing to make sure queries are working as expected when I migrate our dataset over to GeoJSON coordinates and a 2dsphere index. I've noticed what I think is an error in the documentation for $near. It regards the units for $maxDistance.
You mention that $maxDistance should be specified in radians for legacy coordinate pairs. I have been testing on a collection where documents have both legacy and GeoJSON coodinate pairs in separate fields. In this test environment I am running both a 2d and 2dsphere index (just for testing, as it works but I realize it is undocumented and could have unexpected consequences). I am comparing queries using the same centre point and converted radians->metres $maxDistance.
Centre: 37.755244,-122.444
I first followed the documentation and used a $maxDistance of 1407m for the 2dsphere/GeoJSON query and 0.00022 rad (calc: 1407/6371000) for the legacy coodinate/2d query. The 2dsphere query returns 10 documents, the 2d query returns none. Next, instead of radians I tried using decimal degrees. A distance of 1407 m works out to about 0.016 degrees for the above centre location. This time the 2d query returns the same results as the 2dsphere query.
I think the documentation should say "If you query for legacy coordinate pairs, specify $maxDistance in decimal degrees." As I understand it, that is not the same thing as radians. I think that this change could really help people in the future as I've spent a bunch of time figuring it out.
If I've missed something or just don't get it, I'd love to hear about it! Also if you have any questions, please let me know.
Cheers,
Jake
jake@cityseed.com