@@ -19,158 +19,126 @@ Definition
19
19
underlying collection. For aggregations on collection data, see
20
20
:method:`db.collection.aggregate()`.
21
21
22
+ .. |dbcommand| replace:: :dbcommand:`aggregate` command
23
+ .. include:: /includes/fact-mongosh-shell-method-alt.rst
24
+
22
25
The :method:`db.aggregate()` method has the following syntax:
23
26
24
27
.. code-block:: javascript
25
28
26
29
db.aggregate( [ <pipeline> ], { <options> } )
27
30
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 :doc:`multi-document transactions </core/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 :doc:`write concern </reference/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
+ .. list-table::
39
+ :header-rows: 1
40
+ :widths: 20 20 80
41
+
42
+ * - Field
43
+ - Type
44
+ - Description
45
+
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
+ * - ``cursor``
67
+ - document
68
+ - Optional. Specifies the *initial* batch size for the cursor. The value
69
+ of the ``cursor`` field is a document with the field ``batchSize``. See
70
+ :ref:`example-aggregate-method-initial-batch-size` for syntax and example.
71
+
72
+
73
+ * - ``maxTimeMS``
74
+ - non-negative integer
75
+ - Optional. Specifies a time limit in milliseconds for processing
76
+ operations on a cursor. If you do not specify a value for maxTimeMS,
77
+ operations will not time out. A value of ``0`` explicitly
78
+ specifies the default unbounded behavior.
79
+
80
+ MongoDB terminates operations that exceed their allotted time limit
81
+ using the same mechanism as :method:`db.killOp()`. MongoDB only
82
+ terminates an operation at one of its designated :term:`interrupt
83
+ points <interrupt point>`.
84
+
85
+
86
+ * - ``bypassDocumentValidation``
87
+ - boolean
88
+ - Optional. Applicable only if you specify the :pipeline:`$out` or :pipeline:`$merge` aggregation
89
+ stages.
90
+
91
+ Enables :method:`db.collection.aggregate` to bypass document validation
92
+ during the operation. This lets you insert documents that do not
93
+ meet the validation requirements.
94
+
95
+ * - ``readConcern``
96
+ - document
97
+ - Optional. Specifies the :term:`read concern`.
98
+
99
+ .. include:: /includes/fact-readConcern-syntax.rst
100
+
101
+ .. include:: /includes/fact-readConcern-option-description.rst
102
+
103
+ .. include:: /includes/extracts/4.2-changes-out-linearizable.rst
104
+
105
+ .. include:: /includes/extracts/4.2-changes-linearizable-merge-restriction.rst
106
+
107
+
108
+ * - ``collation``
109
+ - document
110
+ - Optional.
111
+
112
+ .. include:: /includes/extracts/collation-option.rst
113
+
114
+
115
+ * - ``hint``
116
+ - string or document
117
+ - Optional. The index to use for the aggregation. The index is on the initial
118
+ collection/view against which the aggregation is run.
119
+
120
+ Specify the index either by the index name or by the index
121
+ specification document.
122
+
123
+ .. note::
124
+
125
+ The ``hint`` does not apply to :pipeline:`$lookup` and
126
+ :pipeline:`$graphLookup` stages.
127
+
128
+
129
+ * - ``comment``
130
+ - string
131
+ - Optional. Users can specify an arbitrary string to help trace the operation
132
+ through the database profiler, currentOp, and logs.
133
+
134
+
135
+ * - ``writeConcern``
136
+ - document
137
+ - Optional. A document that expresses the :ref:`write concern <write-concern>`
138
+ to use with the :pipeline:`$out` or :pipeline:`$merge` stage.
139
+
140
+ Omit to use the default write concern with the :pipeline:`$out` or
141
+ :pipeline:`$merge` stage.
174
142
175
143
176
144
Example
0 commit comments