Skip to content

Commit ee2b1a5

Browse files
jason-price-mongodbandf-mongodb
authored andcommitted
DOCS-13623 Let parameters in aggregate commands
1 parent cf46fcb commit ee2b1a5

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

source/includes/let-variables-example.rst renamed to source/includes/let-constants-example.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ The following example:
1313
- retrieves the cake that has a ``salesTotal`` greater than 3000, which
1414
is the cake with an ``_id`` of 2
1515

16-
- defines a ``targetTotal`` variable in ``let``, which is referenced in
17-
``$gt`` as ``$$targetTotal``
16+
- defines a ``targetTotal`` constant in ``let``, which is referenced in
17+
``$gt`` as ``$$targetTotal``

source/includes/let-constants.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Specifies a document with a list of constants that can be used elsewhere
2+
in the command. This supports tasks that could otherwise only be
3+
performed using the :dbcommand:`mapReduce` command, and reduces the risk
4+
of MQL injection attacks. The document syntax is:
5+
6+
.. code-block:: javascript
7+
:copyable: false
8+
9+
{ <constant_name_1>: <value_1>,
10+
...,
11+
<constant_name_n>: <value_n> }
12+
13+
For example: ``{ targetTotal: 3000 }``
14+
15+
Constants must be named according to the :ref:`user variable naming
16+
conventions<agg-user-variables>`.
17+
18+
To access a constant elsewhere in the command, use the double dollar
19+
sign prefix (``$$``) together with your constant name in the form
20+
``$$<constant_name>``. For example: ``$$targetTotal``

source/includes/let-variables.rst

Lines changed: 0 additions & 21 deletions
This file was deleted.

source/reference/command/aggregate.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,15 @@ arguments:
233233

234234
- document
235235

236-
- Optional.
236+
- .. _aggregate-let-option:
237237

238-
.. include:: /includes/let-variables.rst
238+
Optional.
239+
240+
.. include:: /includes/let-constants.rst
241+
242+
For an example, see :ref:`aggregate-let`.
239243

240-
To view an example, see :ref:`aggregate-let`.
244+
.. versionadded:: 5.0
241245

242246

243247
.. include:: /includes/deprecation-aggregate-wo-cursor.rst
@@ -547,15 +551,15 @@ majority of the nodes.
547551

548552
.. _aggregate-let:
549553

550-
Use Variables in ``let``
554+
Use Constants in ``let``
551555
~~~~~~~~~~~~~~~~~~~~~~~~
552556

553557
.. versionadded:: 5.0
554558

555-
To specify variables that can be accessed elswewhere in the command, use
556-
the :dbcommand:`aggregate` ``let`` option.
559+
To specify constants that can be accessed elsewhere in the command, use
560+
the :ref:`let <aggregate-let-option>` option.
557561

558-
.. include:: /includes/let-variables-example.rst
562+
.. include:: /includes/let-constants-example.rst
559563

560564
.. code-block:: javascript
561565

source/reference/method/db.collection.aggregate.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,15 @@ Definition
213213

214214
- document
215215

216-
- Optional.
216+
- .. _db.collection.aggregate-let-option:
217+
218+
Optional.
217219

218-
.. include:: /includes/let-variables.rst
220+
.. include:: /includes/let-constants.rst
219221

220-
To view an example, see :ref:`db.collection.aggregate-let`.
221-
222+
For an example, see :ref:`db.collection.aggregate-let`.
223+
224+
.. versionadded:: 5.0
222225

223226

224227

@@ -616,15 +619,15 @@ process ID, thread ID, client hostname, and the user who issued the command.
616619

617620
.. _db.collection.aggregate-let:
618621

619-
Use Variables in ``let``
622+
Use Constants in ``let``
620623
~~~~~~~~~~~~~~~~~~~~~~~~
621624

622625
.. versionadded:: 5.0
623626

624627
To specify variables that can be accessed elsewhere in the command, use
625-
the :method:`db.collection.aggregate()` ``let`` option.
628+
the :ref:`let <db.collection.aggregate-let-option>` option.
626629

627-
.. include:: /includes/let-variables-example.rst
630+
.. include:: /includes/let-constants-example.rst
628631

629632
.. code-block:: javascript
630633

source/release-notes/5.0.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ General Aggregation Improvements
2121
``let``
2222
```````
2323

24-
Starting in MongoDB 5.0, :dbcommand:`aggregate` and
25-
:method:`db.collection.aggregate()` have a ``let`` option to specify a
26-
list of variables and values that can be used elsewhere in the
24+
Starting in MongoDB 5.0, the :dbcommand:`aggregate` command and
25+
:method:`db.collection.aggregate()` helper method have a ``let`` option
26+
to specify a list of constants that can be used elsewhere in the
2727
aggregation pipeline. This supports tasks that could otherwise only be
2828
performed using the :dbcommand:`mapReduce` command, and reduces the risk
2929
of MQL injection attacks.

0 commit comments

Comments
 (0)