[DOCS-14557] Indicate that variables from let can only be used in aggregation expressions Created: 11/Jun/21  Updated: 30/Oct/23  Resolved: 13/Jul/21

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Katya Kamenieva Assignee: Jason Price
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 2 years, 34 weeks, 5 days ago
Epic Link: DOCSP-9747
Story Points: 3

 Description   

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



 Comments   
Comment by Jason Price [ 11/Jun/21 ]

andrew.feierabendWill do. Cheers.

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