-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework, Querying
-
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?
- is duplicated by
-
SERVER-47218 Geo-spatial $lookup
- Closed
- is related to
-
SERVER-75557 Allow minDistance and maxDistance parameters in $geoNear pipeline stage to take expressions
- Closed
- related to
-
SERVER-58604 Allow $geoNear 'near' argument to be a let variable
- Closed
-
SERVER-34766 Allow $expr or $$field in the $geoNear stage
- Closed