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

$geoWithin in aggregation pipeline after $lookup and $unwind returns incorrect results

    • Fully Compatible
    • ALL
    • v3.4
    • Hide

      Steps to reproduce within mongo shell:

      db.createCollection("items")
      
      db.createCollection("locations")
      
      db.locations.insert({"coordinates":[25.266, 60.36938],"id":42})
      
      db.items.insert({"id":1, "location_id":42})
      
      db.items.aggregate([{$match:{id: 1}}, {$lookup:{from:"locations",localField:"location_id",foreignField:"id",as:"location"}},{$unwind:"$location"},
      {$match:{"location.coordinates":{$geoWithin:{"$geometry":{"type":"MultiPolygon","coordinates":[[[[20.0,70.0],[30.0,70.0],[30.0,50.0],[20.0,50.0],[20.0,70.0]]]]}}}}}])
      

      This returns nothing in MongoDB 3.4.4. The expected result is (as in 3.2.13):

      { "_id" : ObjectId("594122edb3d185a5e6770c86"), "id" : 1, "location_id" : 42, "location" : { "_id" : ObjectId("594122bdb3d185a5e6770c85"), "coordinates" : [ 25.266, 60.36938 ], "id" : 42 } }
      
      Show
      Steps to reproduce within mongo shell: db.createCollection( "items" ) db.createCollection( "locations" ) db.locations.insert({ "coordinates" :[25.266, 60.36938], "id" :42}) db.items.insert({ "id" :1, "location_id" :42}) db.items.aggregate([{$match:{id: 1}}, {$lookup:{from: "locations" ,localField: "location_id" ,foreignField: "id" ,as: "location" }},{$unwind: "$location" }, {$match:{ "location.coordinates" :{$geoWithin:{ "$geometry" :{ "type" : "MultiPolygon" , "coordinates" :[[[[20.0,70.0],[30.0,70.0],[30.0,50.0],[20.0,50.0],[20.0,70.0]]]]}}}}}]) This returns nothing in MongoDB 3.4.4. The expected result is (as in 3.2.13): { "_id" : ObjectId( "594122edb3d185a5e6770c86" ), "id" : 1, "location_id" : 42, "location" : { "_id" : ObjectId( "594122bdb3d185a5e6770c85" ), "coordinates" : [ 25.266, 60.36938 ], "id" : 42 } }
    • Query 2017-07-10

      Using $geoWithin in a $match stage after $lookup and $unwind in an aggregation pipeline fails to find results that should be found within the geometry. This works properly in 3.2.13.

            Assignee:
            kyle.suarez@mongodb.com Kyle Suarez
            Reporter:
            wox Markus Penttilä
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: