@@ -19,158 +19,127 @@ Definition
1919 underlying collection. For aggregations on collection data, see
2020 :method:`db.collection.aggregate()`.
2121
22+ .. |dbcommand| replace:: :dbcommand:`aggregate` command
23+ .. include:: /includes/fact-mongosh-shell-method-alt.rst
24+
2225 The :method:`db.aggregate()` method has the following syntax:
2326
2427 .. code-block:: javascript
2528
2629 db.aggregate( [ <pipeline> ], { <options> } )
2730
28- - The ``pipeline`` parameter is an array of stages to execute. It
29- must start with a compatible stage that does not require an
30- underlying collection, such as :pipeline:`$currentOp` or
31- :pipeline:`$listLocalSessions`.
32-
33- - The ``options`` document can contain the following fields and values:
34-
35-
36- .. list-table::
37- :header-rows: 1
38- :widths: 20 20 80
39-
40- * - Field
41-
42- - Type
43-
44- - Description
45-
46- * - ``explain``
47-
48- - boolean
49-
50- - Optional. Specifies to return the information on the processing of the pipeline. See
51- :ref:`example-aggregate-method-explain-option` for an example.
52-
53- Not available in :ref:`multi-document transactions <transactions>`.
54-
55-
56-
57- * - ``allowDiskUse``
58-
59- - boolean
60-
61- - Optional. Enables writing to temporary files. When set to ``true``, aggregation
62- operations can write data to the :file:`_tmp` subdirectory in the
63- :setting:`~storage.dbPath` directory. See
64- :ref:`example-aggregate-method-external-sort` for an example.
65-
66- .. include:: /includes/extracts/4.2-changes-usedDisk.rst
67-
68-
69-
70- * - ``cursor``
71-
72- - document
73-
74- - Optional. Specifies the *initial* batch size for the cursor. The value of the ``cursor``
75- field is a document with the field ``batchSize``. See
76- :ref:`example-aggregate-method-initial-batch-size` for syntax and example.
77-
78-
79- * - ``maxTimeMS``
80-
81- - non-negative integer
82-
83- - Optional. Specifies a time limit in milliseconds for processing
84- operations on a cursor. If you do not specify a value for maxTimeMS,
85- operations will not time out. A value of ``0`` explicitly
86- specifies the default unbounded behavior.
87-
88- MongoDB terminates operations that exceed their allotted time limit
89- using the same mechanism as :method:`db.killOp()`. MongoDB only
90- terminates an operation at one of its designated :term:`interrupt
91- points <interrupt point>`.
92-
93-
94-
95- * - ``bypassDocumentValidation``
96-
97- - boolean
98-
99- - Optional. Applicable only if you specify the :pipeline:`$out` or :pipeline:`$merge` aggregation
100- stages.
101-
102-
103-
104- Enables :method:`db.collection.aggregate` to bypass document validation
105- during the operation. This lets you insert documents that do not
106- meet the validation requirements.
107-
108-
109-
110- * - ``readConcern``
111-
112- - document
113-
114- - Optional. Specifies the :term:`read concern`.
115-
116- .. include:: /includes/fact-readConcern-syntax.rst
117-
118- .. include:: /includes/fact-readConcern-option-description.rst
119-
120- .. include:: /includes/extracts/4.2-changes-out-linearizable.rst
121-
122- .. include:: /includes/extracts/4.2-changes-linearizable-merge-restriction.rst
123-
124-
125-
126- * - ``collation``
127-
128- - document
129-
130- - Optional.
131-
132- .. include:: /includes/extracts/collation-option.rst
133-
134-
135-
136- * - ``hint``
137-
138- - string or document
139-
140- - Optional. The index to use for the aggregation. The index is on the initial
141- collection/view against which the aggregation is run.
142-
143- Specify the index either by the index name or by the index
144- specification document.
145-
146- .. note::
147-
148- The ``hint`` does not apply to :pipeline:`$lookup` and
149- :pipeline:`$graphLookup` stages.
150-
151-
152-
153- * - ``comment``
154-
155- - string
156-
157- - Optional. Users can specify an arbitrary string to help trace the operation
158- through the database profiler, currentOp, and logs.
159-
160-
161-
162- * - ``writeConcern``
163-
164- - document
165-
166- - Optional. A document that expresses the :ref:`write concern <write-concern>`
167- to use with the :pipeline:`$out` or :pipeline:`$merge` stage.
168-
169- Omit to use the default write concern with the :pipeline:`$out` or
170- :pipeline:`$merge` stage.
171-
172-
173-
31+ The ``pipeline`` parameter is an array of stages to execute. It
32+ must start with a compatible stage that does not require an
33+ underlying collection, such as :pipeline:`$currentOp` or
34+ :pipeline:`$listLocalSessions`.
35+
36+ The ``options`` document can contain the following fields and values:
37+
38+
39+ .. list-table::
40+ :header-rows: 1
41+ :widths: 20 20 80
42+
43+ * - Field
44+ - Type
45+ - Description
46+
47+ * - ``explain``
48+ - boolean
49+ - Optional. Specifies that the method should return
50+ information on the processing of the pipeline.
51+
52+ See :ref:`example-aggregate-method-explain-option` for an example.
53+
54+ Not available in :ref:`multi-document transactions <transactions>`.
55+
56+
57+ * - ``allowDiskUse``
58+ - boolean
59+ - Optional. Enables writing to temporary files. When set to ``true``, aggregation
60+ operations can write data to the :file:`_tmp` subdirectory in the
61+ :setting:`~storage.dbPath` directory. See
62+ :ref:`example-aggregate-method-external-sort` for an example.
63+
64+ .. include:: /includes/extracts/4.2-changes-usedDisk.rst
65+
66+
67+ * - ``cursor``
68+ - document
69+ - Optional. Specifies the *initial* batch size for the cursor. The value of the ``cursor``
70+ field is a document with the field ``batchSize``. See
71+ :ref:`example-aggregate-method-initial-batch-size` for syntax and example.
72+
73+
74+ * - ``maxTimeMS``
75+ - non-negative integer
76+ - Optional. Specifies a time limit in milliseconds for processing
77+ operations on a cursor. If you do not specify a value for maxTimeMS,
78+ operations will not time out. A value of ``0`` explicitly
79+ specifies the default unbounded behavior.
80+
81+ MongoDB terminates operations that exceed their allotted time limit
82+ using the same mechanism as :method:`db.killOp()`. MongoDB only
83+ terminates an operation at one of its designated :term:`interrupt
84+ points <interrupt point>`.
85+
86+
87+ * - ``bypassDocumentValidation``
88+ - boolean
89+ - Optional. Applicable only if you specify the :pipeline:`$out` or :pipeline:`$merge` aggregation
90+ stages.
91+
92+ Enables :method:`db.collection.aggregate` to bypass document validation
93+ during the operation. This lets you insert documents that do not
94+ meet the validation requirements.
95+
96+ * - ``readConcern``
97+ - document
98+ - Optional. Specifies the :term:`read concern`.
99+
100+ .. include:: /includes/fact-readConcern-syntax.rst
101+
102+ .. include:: /includes/fact-readConcern-option-description.rst
103+
104+ .. include:: /includes/extracts/4.2-changes-out-linearizable.rst
105+
106+ .. include:: /includes/extracts/4.2-changes-linearizable-merge-restriction.rst
107+
108+
109+ * - ``collation``
110+ - document
111+ - Optional.
112+
113+ .. include:: /includes/extracts/collation-option.rst
114+
115+
116+ * - ``hint``
117+ - string or document
118+ - Optional. The index to use for the aggregation. The index is on the initial
119+ collection/view against which the aggregation is run.
120+
121+ Specify the index either by the index name or by the index
122+ specification document.
123+
124+ .. note::
125+
126+ The ``hint`` does not apply to :pipeline:`$lookup` and
127+ :pipeline:`$graphLookup` stages.
128+
129+
130+ * - ``comment``
131+ - string
132+ - Optional. Users can specify an arbitrary string to help trace the operation
133+ through the database profiler, currentOp, and logs.
134+
135+
136+ * - ``writeConcern``
137+ - document
138+ - Optional. A document that expresses the :ref:`write concern <write-concern>`
139+ to use with the :pipeline:`$out` or :pipeline:`$merge` stage.
140+
141+ Omit to use the default write concern with the :pipeline:`$out` or
142+ :pipeline:`$merge` stage.
174143
175144
176145Example
0 commit comments