-
Type: Investigation
-
Resolution: Declined
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
Downstream Change Summary
The aggregation stage $geoNear now allows the 'near' argument to be a let variable (previously only a constant was allowed).
Description of Linked Ticket
Currently, 'near' has to be a literal array (or GeoJSON object):
> db.c.aggregate([ {$geoNear: {near: [0, 0]}} ]
Instead we should allow it to be an expression:
> db.c.aggregate([ {$geoNear: {near: "$$pt"}} ], {let: {pt: [0, 0]}})
It doesn't make sense to allow the query point to vary per-document, so it has to be a constant expression.
We also want to allow 'near' to be bound in a $lookup:
{$lookup: { from: 'coll', as: 'docs', let: {pt: "$location"}, pipeline: [ {$geoNear: { near: "$$pt", ... }} ] }}
The expression "$$pt" is constant within each subquery.
To make this work I think we'll want to:
- Change the DocumentSourceGeoNear parser to accept any expression, for 'near'.
- Change DocumentSourceGeoNear::optimize to optimize the expression.
- When we convert DocumentSourceGeoNear to DocumentSourceGeoNearCursor, raise an error if the expression is not a constant.
- depends on
-
SERVER-58604 Allow $geoNear 'near' argument to be a let variable
- Closed