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

$geoWithin query using $polygon or $geometry gives different result

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

      Add a geometry in the collection :

      db.cust_5_abcd.insert({
      "chps0" : "Texte d'une ligne",
      "the_geom" : {
          "type" : "Point",
          "coordinates" : [ 
              1.032715, 
              40.380028
          ]
      }})
      

      With $geometry gives NO result:

      db.cust_5_abcd.find(  { the_geom: 
       { $geoWithin: 
              { $geometry: 
                  {       
                      "type": "Polygon", 
                      "coordinates": [ 
                          [ 
                              [ -16.237793, 40.162083 ], 
                              [ -16.237793, 51.835778 ], 
                              [ -13.776855, 51.835778 ], 
                              [ -13.776855, 41.426253 ], 
                              [ 14.765625, 41.426253 ], 
                              [ 14.765625, 40.162083 ], 
                              [ -16.237793, 40.162083 ] 
                      ] 
                      ]
                  } 
              } 
          } 
      })
      

      With $polygon returns my Point :

      db.cust_5_abcd.find( { the_geom: 
       { $geoWithin: 
              { $polygon:
                          [ 
                              [ -16.237793, 40.162083 ], 
                              [ -16.237793, 51.835778 ], 
                              [ -13.776855, 51.835778 ], 
                              [ -13.776855, 41.426253 ], 
                              [ 14.765625, 41.426253 ], 
                              [ 14.765625, 40.162083 ], 
                              [ -16.237793, 40.162083 ] 
                      ]                 
              } 
          } 
      })
      
      Show
      Add a geometry in the collection : db.cust_5_abcd.insert({ "chps0" : "Texte d'une ligne", "the_geom" : { "type" : "Point", "coordinates" : [ 1.032715, 40.380028 ] }}) With $geometry gives NO result: db.cust_5_abcd.find( { the_geom: { $geoWithin: { $geometry: { "type": "Polygon", "coordinates": [ [ [ -16.237793, 40.162083 ], [ -16.237793, 51.835778 ], [ -13.776855, 51.835778 ], [ -13.776855, 41.426253 ], [ 14.765625, 41.426253 ], [ 14.765625, 40.162083 ], [ -16.237793, 40.162083 ] ] ] } } } }) With $polygon returns my Point : db.cust_5_abcd.find( { the_geom: { $geoWithin: { $polygon: [ [ -16.237793, 40.162083 ], [ -16.237793, 51.835778 ], [ -13.776855, 51.835778 ], [ -13.776855, 41.426253 ], [ 14.765625, 41.426253 ], [ 14.765625, 40.162083 ], [ -16.237793, 40.162083 ] ] } } })

      Using MongoDB 3.2 i'm trying to use 2dsphere queries on a collection of Points.

      Lets say i have à collection cust_5_abcd with a 2dsphere index on the_geom field.

      Now i'm trying to query this Point using $geoWithin to get all data inside a specific Polygon. This is where i'm getting different result if i use $geometry with the GeoJSON definition , or with $polygon and the strict coordinates. Maybe something in the documentation is missing or something i misunderstood.

      With $geometry gives NO result.
      With $polygon returns my Point.

            Assignee:
            Unassigned Unassigned
            Reporter:
            gbac gbac
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: