[SERVER-58604] Allow $geoNear 'near' argument to be a let variable Created: 15/Jul/21  Updated: 29/Oct/23  Resolved: 06/Sep/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: New Feature Priority: Major - P3
Reporter: David Percy Assignee: Milena Ivanova
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by COMPASS-5103 Allow $geoNear 'near' argument to be ... Closed
is depended on by TOOLS-2954 Investigate changes in SERVER-58604: ... Closed
Documented
is documented by DOCS-14779 Investigate changes in SERVER-58604: ... Closed
Duplicate
is duplicated by SERVER-34766 Allow $expr or $$field in the $geoNea... Closed
Related
is related to SERVER-37675 Allow $geoWithin and $geoIntersects t... Backlog
Backwards Compatibility: Fully Compatible
Sprint: Query Optimization 2021-07-26, QO 2021-09-06, Query Optimization 2021-08-09, QO 2021-09-20, QO 2021-08-23
Participants:

 Description   

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.


 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 21/Sep/21 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-58604 Allow $geoNear 'near' argument to be a let variable
Branch: SERVER-58852
https://github.com/10gen/mongo-enterprise-modules/commit/070564fe0038017ee30edf454b5f08014df6dd94

Comment by Githook User [ 06/Sep/21 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-58604 Allow $geoNear 'near' argument to be a let variable
Branch: master
https://github.com/mongodb/mongo/commit/584e43d33bc20c6422205d7d7626c9580eaf538e

Comment by Githook User [ 06/Sep/21 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-58604 Allow $geoNear 'near' argument to be a let variable
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/070564fe0038017ee30edf454b5f08014df6dd94

Generated at Thu Feb 08 05:44:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.