Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-67025

$geoWithin a rectangular Polygon results differ from box

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.0.12
    • Component/s: None
    • None
    • ALL

      When issuing a $geoWithin using a Polygon as the search region, GeoJSON Points near-ish to the region are unexpectedly included or excluded. Since the Polygon in question is actually rectangular, changing to use $geoWithin with a $box fixed the issue. Is this expected? Is there any suggested workaround other than using a box?

      Here is a sample point and the Polygon-based find that incorrectly matches:

      > db.coll.insertOne({"location": {"type": "Point", "coordinates": [11.84, 50.1588, 9433.56]}})
      > db.coll.find({
      ...         "location": {
      ...           "$geoWithin": {
      ...             "$geometry": {
      ...               "type": "Polygon",
      ...               "coordinates": [
      ...                 [
      ...                     [ 0.849607, 43.447224],
      ...                     [23.23242,  43.447224],
      ...                     [23.23242,  49.873922],
      ...                     [ 0.849607, 49.873922],
      ...                     [ 0.849607, 43.447224]
      ...                 ]
      ...               ]
      ...             }
      ...           }
      ...         }
      ...       })

       

      This box-based find, however, works as expected:

      > db.coll.find({"location": {"$geoWithin": {"$box": [[0.849607, 43.447224], [23.23242, 49.873922]]}}}) 

      and does not match the document.

        1. box.png
          box.png
          1.51 MB

            Assignee:
            chris.kelly@mongodb.com Chris Kelly
            Reporter:
            markaalvaro@gmail.com Mark Alvaro
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: