[SERVER-37675] Allow $geoWithin and $geoIntersects to take their geometry from an expression Created: 19/Oct/18  Updated: 28/Dec/23

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework, Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Robert Ludwig Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 3
Labels: geo, qi-geo, query-product-scope-2, query-product-urgency-3, query-product-value-2
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-47218 Geo-spatial $lookup Closed
Related
related to SERVER-58604 Allow $geoNear 'near' argument to be ... Closed
related to SERVER-34766 Allow $expr or $$field in the $geoNea... Closed
is related to SERVER-75557 Allow minDistance and maxDistance par... Closed
Assigned Teams:
Query Integration
Participants:

 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?

 

 

 

 



 Comments   
Comment by David Percy [ 16/Nov/22 ]

Reopening because SERVER-34766 / SERVER-58604 addresses a different (though related) feature request.

This ticket is specifically about allowing geo match-expressions ($geoWithin, $geoIntersects) to take their geometry (which can be a polygon, or other shape) from an expression.

SERVER-34766 / SERVER-58604 handled $geoNear, which only lets you query around a given point, with a fixed min/max radius. $geoNear is mainly about sorting results by how close to the central point they are, so it doesn't support polygons.

Comment by Danny Hatcher (Inactive) [ 22/Oct/18 ]

Hello Robert,

Unfortunately, this is a known issue. All work towards resolving it should occur in SERVER-34766. Please refer to that ticket for any further information on your pain point and vote for it if it is important to your business case.

Generated at Thu Feb 08 04:46:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.