Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-14779

Investigate changes in SERVER-58604: Allow $geoNear 'near' argument to be a let variable

      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.

            Assignee:
            ian.fogelman@mongodb.com Ian Fogelman
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              2 years, 28 weeks, 1 day ago