Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-2954

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

    • Type: Icon: Investigation Investigation
    • Resolution: Declined
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      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.

            Assignee:
            Unassigned Unassigned
            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: