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

Understanding $geoWithin and $geoIntersects Undefined Behavior when Run with Invalid Geometry

    • Type: Icon: Engineering Test Engineering Test
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration

      Request

      $geoIntersects and $geoWithin don't require geospatial indexes to be used. In the sample below, when you run $geoIntersects and there is invalid geometry in a collection that has no geospatial index, no runtime error is raised and documents are still being returned. This is likely the same for $geoWithin.

      For both operators, it would be useful to understand whether malformed documents are being skipped and if not, how do the operators behave on invalid geometry (i.e. $geoWithin on a ringed Polygon).

       

       

      MongoDB Enterprise > db.geo.aggregate([{$match: {loc: {$geoIntersects: {$geometry: {type: "Polygon", coordinates: [[[-1,-1],[5,-5],[5,5],[-5,5],[-1,-1]]]}}}}}])
      { "_id" : ObjectId("664256fe723ea1d92550973d"), "loc" : { "type" : "Polygon", "coordinates" : [ [ [ 0, 0 ], [ 5, 0 ], [ 5, 5 ], [ 0, 5 ], [ 0, 0 ] ] ] } }
      { "_id" : ObjectId("668c1a4b3f835fd03415379b"), "loc" : { "type" : "Polygon", "coordinates" : [ [ [ 0, 0 ], [ 5, 0 ], [ 5, 5 ], [ 0, 5 ], [ 0, 0 ] ] ] } }
      
      MongoDB Enterprise > db.geo.insert({loc: {type: "Polygon", coordinates: [[[0,0],[5,0],[0,0],[0,5],[0,0]]]}})
      WriteResult({ "nInserted" : 1 })
      
      MongoDB Enterprise > db.geo.aggregate([{$match: {loc: {$geoIntersects: {$geometry: {type: "Polygon", coordinates: [[[-1,-1],[5,-5],[5,5],[-5,5],[-1,-1]]]}}}}}])
      { "_id" : ObjectId("664256fe723ea1d92550973d"), "loc" : { "type" : "Polygon", "coordinates" : [ [ [ 0, 0 ], [ 5, 0 ], [ 5, 5 ], [ 0, 5 ], [ 0, 0 ] ] ] } }
      { "_id" : ObjectId("668c1a4b3f835fd03415379b"), "loc" : { "type" : "Polygon", "coordinates" : [ [ [ 0, 0 ], [ 5, 0 ], [ 5, 5 ], [ 0, 5 ], [ 0, 0 ] ] ] } }
      
      MongoDB Enterprise > db.geo.createIndex({loc: "2dsphere"})
      {
              "ok" : 0,
              "errmsg" : "Index build failed: cea2badd-bd58-479a-885f-9765ee79155a: Collection test.geo ( 2a876118-4100-4d38-9430-9f41d138ce06 ) :: caused by :: collection scan stopped. totalRecords: 2; durationMillis: 1ms; phase: collection scan; collectionScanPosition: RecordId(3); readSource: kNoTimestamp :: caused by :: Can't extract geo keys: { _id: ObjectId('66a11b9fb2766f41630cbce3'), loc: { type: \"Polygon\", coordinates: [ [ [ 0.0, 0.0 ], [ 5.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 5.0 ], [ 0.0, 0.0 ] ] ] } }  Loop is not valid: [ [ 0.0, 0.0 ], [ 5.0, 0.0 ], [ 0.0, 0.0 ], [ 0.0, 5.0 ], [ 0.0, 0.0 ] ] Duplicate vertices: 0 and 2",
              "code" : 16755,
              "codeName" : "Location16755"
      } 

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            ayaan.hussain@mongodb.com Ayaan Hussain (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: