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

Allow $geoWithin and $geoIntersects to take their geometry from an expression

    • Query Integration

      Suppose I have collections for users, and coffeeshops with geodata for each. I'd like to make a pipeline counting the number of coffeeshops a user is near. 

      A natural way to do this is with $lookup and a subpipeline: 

       

       

      db.users.aggregate([{$lookup : { from : "coffeeshopAreas", let : {userCoordinates : "$geometry.coordinates"}, as : "nearbyShops", pipeline : [ {$match : {geometry : {$geoIntersects : {$geometry : {type : "Point", coordinates : "$$userCoordinates"}}}}}, {group : {_id : null, numNearbyShops : {$sum : 1}}}, ]    }])
      

       

      However, this approach is currently impossible. $geometry does not resolve the variable defined in the $let expression, and instead rejects the Point

      Assert: command failed:

      {"ok" : 0,"errmsg" : "Point must only contain numeric elements", "code" : 2, "codeName" : "BadValue"}

      : aggregate failed

       

      This is a big limitation! Why can't I make a $geometry from some other object?

       

       

       

       

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            rob.ludwig@rideamigos.com Robert Ludwig
            Votes:
            4 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: