Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-284

GeoWithin query returns wrong result

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      Ubuntu 14.04.1 LTS

      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 5000 of such points.
      Thanks in advance!

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

              Created:
              Updated:
              Resolved: