@@ -72,6 +72,7 @@ Consider the following limitations when performing aggregation operations:
72
72
- Returned documents cannot violate the
73
73
:manual:`BSON document size limit </reference/limits/#mongodb-limit-BSON-Document-Size>`
74
74
of 16 megabytes.
75
+
75
76
- Pipeline stages have a memory limit of 100 megabytes by default. You can exceed this
76
77
limit by creating an options array that sets the ``allowDiskUse`` option to ``true``
77
78
and passing the array to the ``MongoDB\Collection::aggregate()`` method.
@@ -89,9 +90,9 @@ The {+library-short+} provides the following APIs to create aggregation
89
90
pipelines:
90
91
91
92
- :ref:`php-aggregation-array-api`: Create aggregation pipelines by
92
- passing arrays that specify the aggregation operators and parameters
93
+ passing arrays that specify the aggregation operators and parameters.
93
94
- :ref:`php-aggregation-builder-api`: Create aggregation pipelines by using native
94
- classes and methods to make your application more type-safe and debuggable
95
+ classes and methods to make your application more type-safe and debuggable.
95
96
96
97
The following sections describe each API and provide examples for
97
98
creating aggregation pipelines.
@@ -126,12 +127,12 @@ Filter and Group Example
126
127
The following code example produces a count of the number of bakeries in each borough
127
128
of New York. To do so, it uses an aggregation pipeline that contains the following stages:
128
129
129
- - :manual:`$match </reference/operator/aggregation/match/>` stage to filter for documents
130
- in which the ``cuisine`` field contains the value ``'Bakery'``
130
+ 1. :manual:`$match </reference/operator/aggregation/match/>` stage to filter for documents
131
+ in which the ``cuisine`` field contains the value ``'Bakery'``
131
132
132
- - :manual:`$group </reference/operator/aggregation/group/>` stage to group the matching
133
- documents by the ``borough`` field, accumulating a count of documents for each distinct
134
- value
133
+ #. :manual:`$group </reference/operator/aggregation/group/>` stage to group the matching
134
+ documents by the ``borough`` field, accumulating a count of documents for each distinct
135
+ value
135
136
136
137
.. io-code-block::
137
138
:copyable:
@@ -195,14 +196,16 @@ Aggregation Builder
195
196
To create an aggregation pipeline by using the Aggregation Builder,
196
197
perform the following actions:
197
198
198
- # . Create an array to store the pipeline stages
199
+ 1 . Create an array to store the pipeline stages.
199
200
200
- #. For each stage, call an operator method from the ``Stage``
201
- builder class to create that type of aggregation stage
201
+ #. For each stage, call the an operator method from the
202
+ ``Stage`` that shares the same name as your desired aggregation
203
+ stage. For example, to create an ``$unwind`` stage, call the
204
+ ``Stage::unwind()`` method.
202
205
203
206
#. Within the body of the ``Stage`` method, use methods from other
204
207
builder classes such as ``Query``, ``Expression``, or ``Accumulator``
205
- to express your aggregation specifications
208
+ to express your aggregation specifications.
206
209
207
210
The following code demonstrates the template for constructing
208
211
aggregation pipelines:
@@ -236,17 +239,17 @@ The following code example calculates the total sales amount, average
236
239
sales quantity, and sale count for each day in the year 2014. To do so,
237
240
it uses an aggregation pipeline that contains the following stages:
238
241
239
- - :manual:`$match </reference/operator/aggregation/match/>` stage to
240
- filter for documents that contain a ``date`` field in which the year is
241
- 2014
242
+ 1. :manual:`$match </reference/operator/aggregation/match/>` stage to
243
+ filter for documents that contain a ``date`` field in which the year is
244
+ 2014
242
245
243
- - :manual:`$group </reference/operator/aggregation/group/>` stage to
244
- group the documents by date and calculate the total sale amount,
245
- average quantity, and total count for each group
246
+ #. :manual:`$group </reference/operator/aggregation/group/>` stage to
247
+ group the documents by date and calculate the total sale amount,
248
+ average quantity, and total count for each group
246
249
247
- - :manual:`$sort </reference/operator/aggregation/sort/>` stage to
248
- sort the results by the total sale amount for each group in descending
249
- order
250
+ #. :manual:`$sort </reference/operator/aggregation/sort/>` stage to
251
+ sort the results by the total sale amount for each group in descending
252
+ order
250
253
251
254
.. io-code-block::
252
255
:copyable:
@@ -275,15 +278,15 @@ The following code example groups sold items by their tags and
275
278
calculates the total sales amount for each tag. To do so,
276
279
it uses an aggregation pipeline that contains the following stages:
277
280
278
- - :manual:`$unwind </reference/operator/aggregation/unwind/>` stage to
279
- output a separate document for each element in the ``items`` array
281
+ 1. :manual:`$unwind </reference/operator/aggregation/unwind/>` stage to
282
+ output a separate document for each element in the ``items`` array
280
283
281
- - :manual:`$unwind </reference/operator/aggregation/unwind/>` stage to
282
- output a separate document for each element in the ``items.tags`` arrays
284
+ #. :manual:`$unwind </reference/operator/aggregation/unwind/>` stage to
285
+ output a separate document for each element in the ``items.tags`` arrays
283
286
284
- - :manual:`$group </reference/operator/aggregation/group/>` stage to
285
- group the documents by the tag value and calculates the total sales
286
- amount of items that have each tag
287
+ #. :manual:`$group </reference/operator/aggregation/group/>` stage to
288
+ group the documents by the tag value and calculates the total sales
289
+ amount of items that have each tag
287
290
288
291
.. io-code-block::
289
292
:copyable:
0 commit comments