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

$geoWithin does not return all documents within polygon

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.5
    • Component/s: Geo
    • Labels:
      None
    • Fully Compatible
    • ALL

      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?

            Assignee:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Reporter:
            andre.spiegel@mongodb.com Andre Spiegel
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: