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

GeoWithin query returns wrong result

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.9
    • Component/s: Querying, Shell
    • Environment:
      Ubuntu 14.04.1 LTS
    • Linux
    • Hide

      1. Create collection.

      db.createCollection('newTest');
      

      2. Ensure index (2dsphere).

      db.newTest.ensureIndex({'point':'2dsphere'});
      

      3. Add document into it.

      db.newTest.insert({"point" : {"type" : "Point","coordinates" : [-80.087535,42.054246]}});
      

      4. Query geoWithin.

      db.newTest.find({"point":{"$geoWithin":{"$geometry":{"type":"Polygon","coordinates":[[[-80.267831,42.050312],[-80.267831,45.003652],[-73.362579,45.003652],[-73.362579,42.050312],[-80.267831,42.050312]]]}}}});
      
      Show
      1. Create collection. db.createCollection( 'newTest' ); 2. Ensure index (2dsphere). db.newTest.ensureIndex({ 'point' : '2dsphere' }); 3. Add document into it. db.newTest.insert({ "point" : { "type" : "Point" , "coordinates" : [-80.087535,42.054246]}}); 4. Query geoWithin. db.newTest.find({ "point" :{ "$geoWithin" :{ "$geometry" :{ "type" : "Polygon" , "coordinates" :[[[-80.267831,42.050312],[-80.267831,45.003652],[-73.362579,45.003652],[-73.362579,42.050312],[-80.267831,42.050312]]]}}}});

      I've stuck with a problem of matching items inside a polygon (simple box). I can't figure out why the item which is inside the queried box is not resulting. So here what i have:

      >db.testing.getIndexes();
      {
          "0" : {
              "v" : 1,
              "key" : {
                  "_id" : 1
              },
              "ns" : "test.testing",
              "name" : "_id_"
          },
          "1" : {
              "v" : 1,
              "key" : {
                  "point" : "2dsphere"
              },
              "ns" : "test.testing",
              "name" : "2dsphere_index"
          }
      }
      

      Here is my documents (i've tested different formats):

      >db.testing.find();
      {
          "_id" : ObjectId("5439c9c61120c95f4c50a369"),
          "point" : {
              "lng" : -80.087535,
              "lat" : 42.054246
          }
      }
      {
          "_id" : ObjectId("5439cc6d1120c95f4c50a36a"),
          "point" : {
              "type" : "Point",
              "coordinates" : [
                  -80.087535,
                  42.054246
              ]
          }
      } }}
      And here is query:
      

      >db.testing.find({"point": {"$geoWithin": {
      "$geometry":

      { "type": "Polygon", "coordinates": [ [ [-80.267831,42.050312], [-80.267831,45.003652], [-73.362579,45.003652], [-73.362579,42.050312], [-80.267831,42.050312] ] ] }

      }}})

      
      

      But the problem is that it returns zero results!
      If you not sure, that point is really in square, than copy this:

      {"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[-80.087535,42.054246]},{"type":"Polygon","coordinates":[[[-80.267831,42.050312],[-80.267831,45.003652],[-73.362579,45.003652],[-73.362579,42.050312],[-80.267831,42.050312]]]}]}
      

      and check it here.
      I'm confused, could somebody help me with this please?
      Also, those points is got found when we decrease polygon area to:

      [[-80.159937,42.050312],[-80.05204,42.050312],[-80.05204,42.09646],[-80.159937,42.09646],[-80.159937,42.050312]]
      

      If it's needed i could provide near 100 more of such points.
      Thanks in advance!

        1. polygon.png
          polygon.png
          1.02 MB
        2. polygon2.png
          polygon2.png
          1.51 MB

            Assignee:
            Unassigned Unassigned
            Reporter:
            ofetisov Oleg Fetisov
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: