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

$geometry and $geo-related operators don't take expressions

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      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?

       

       

       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              daniel.hatcher Danny Hatcher (Inactive)
              Reporter:
              rob.ludwig@rideamigos.com Robert Ludwig
              Participants:
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: