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

$geoWithin does not return all documents within polygon

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 2.6.5
    • Fix Version/s: None
    • Component/s: Geo
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL

      Description

      I'm creating a collection with 1000 random points roughly in the area where Canada would be on the globe:

      for (i=0; i<1000; i++) {
         var lon = -25 - Math.random() * 75;
         var lat = 35 + Math.random() * 35;
         db.data.insert({"loc": { "type" : "Point",
                                   "coordinates" : [ lon, lat ] } });
      }

      In other words, longitude is between -100 and -25, and latitude is between 35 and 70. I'm defining a 2dsphere index on it:

      db.data.ensureIndex({"loc":"2dsphere"})

      and then query with a bounding rectange that should encompass all the points:

      db.data.find({"loc":
        {"$geoWithin":
          {"$geometry":{"type":"Polygon",
                        "coordinates":[[[-110, 30], [-110, 75], [-20, 75], [-20, 30], [-110, 30]]]}}}}
      )

      (The polygon runs from -110 to -20 longitude and 30 to 75 latitude.) However, the query does not return all 1000 documents (in one particular example, I only got 919). If I make the rectangle even larger, it actually returns even less documents. This can be confirmed both by .count() and .toArray().length.

      Is there anything wrong in my setup or assumptions how $geoWithin works?

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: