[DOCS-14779] Investigate changes in SERVER-58604: Allow $geoNear 'near' argument to be a let variable Created: 06/Sep/21  Updated: 13/Nov/23  Resolved: 05/Nov/21

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 5.1.0-rc0, Server_Docs_20231030, Server_Docs_20231106, Server_Docs_20231105, Server_Docs_20231113

Type: Task Priority: Major - P3
Reporter: Backlog - Core Eng Program Management Team Assignee: Ian Fogelman
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-58604 Allow $geoNear 'near' argument to be ... Closed
Participants:
Days since reply: 2 years, 13 weeks, 5 days ago
Epic Link: DOCSP-14300

 Description   
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.


 Comments   
Comment by Githook User [ 05/Nov/21 ]

Author:

{'name': 'ianf-mongodb', 'email': '85948430+ianf-mongodb@users.noreply.github.com', 'username': 'ianf-mongodb'}

Message: DOCS-14779 Add context around 5.1 let usage in geoNear (#6073)

  • DOCS-14779 Add context around 5.1 let usage in geoNear
  • Update source/reference/operator/aggregation/geoNear.txt

Co-authored-by: jeff-allen-mongo <jeffrey.allen@10gen.com>

Co-authored-by: jeff-allen-mongo <jeffrey.allen@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/911c14d979bb2551dbd3b8f8451b5df80e623a50

Comment by PM Bot [ 06/Sep/21 ]

Downstream changes updated for upstream SERVER-58604:
The aggregation stage $geoNear now allows the 'near' argument to be a let variable (previously only a constant was allowed).

Generated at Thu Feb 08 08:11:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.