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

$geoNear distanceMultiplier

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Minor - P4 Minor - P4
    • Server_Docs_20231030
    • Affects Version/s: None
    • Component/s: manual, Server
    • Labels:
      None

      There are discrepancies on the units used for various fields for $geoNear.

      The description for the distanceMultiplier field for $geoNear says

      The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth.

      Also, the description for minDistance says,

      Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs

      however a 2dsphere index will convert legacy coordinate pairs to GeoJSON Point. So I can have a field like this:

      "p": [ -100.8, 33.1875 ]
      

      whose 2dsphere index will convert it into

      { type: "Point", coordinates: [ -100.8, 33.1875 ] }
      

      such that I can specify minDistance in meters even though the documentation says it should be in radians.

      The near field sheds some light:

      If using a 2dsphere index, you can specify the point as either a GeoJSON point or legacy coordinate pair. If using a 2d index, specify the point as a legacy coordinate pair.

      So the main factor appears to be the index used (2dsphere vs 2d) instead of whether the point is GeoJSON or legacy coordinate pair.

      Comment on: "reference/operator/aggregation/geoNear.txt"

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            jake.angerman Jake Angerman
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              1 year, 24 weeks ago