Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-1828

Comment on: "manual/reference/operator/near.txt"

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            jakeorr Jake Orr
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              7 years, 40 weeks, 1 day ago