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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 3.4.4
    • Fix Version/s: 3.4.6, 3.5.10
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Requested:
      v3.4
    • Steps To Reproduce:
      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 } }
    • Sprint:
      Query 2017-07-10

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: