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

Indicate that variables from let can only be used in aggregation expressions

      Description

      https://docs.mongodb.com/v5.0/reference/command/aggregate/#use-variables-in-let
      Let variables only can be used in the aggregation expressions
      e.g., you can’t do

      db.cakeSales.aggregate(
         [
            { $match: { flavor: "$$flvr" } }
         ],
         { let: { flvr: "cherry" } }
      )

      it has to be

      db.cakeSales.aggregate(
         [
            { $match: {
               $expr: { $eq: [ "$flavor", "$$flvr" ] },
            } }
         ],
         { let: { flvr: "cherry" } }
      )

      In docs it says “To specify variables that can be accessed elsewhere in the command, use the let option.”
      Variables also cannot be used in other places like ‘from’ field for $lookup etc.
      I think we need to clarify where exactly those work.

      Scope of changes

      Impact to Other Docs

      MVP (Work and Date)

      Resources (Scope or Design Docs, Invision, etc.)

            Assignee:
            jason.price@mongodb.com Jason Price
            Reporter:
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              2 years, 45 weeks, 6 days ago