@@ -13,17 +13,36 @@ Aggregation Pipeline
13
13
The aggregation pipeline is a framework for data aggregation modeled
14
14
on the concept of data processing pipelines. Documents enter a
15
15
multi-stage pipeline that transforms the documents into aggregated
16
- results.
16
+ results. For example:
17
17
18
- .. include :: /images/aggregation-pipeline.rst
18
+ .. only :: website and dirhtml
19
19
20
- The aggregation pipeline provides an alternative to :term:`map-reduce`
21
- and may be the preferred solution for aggregation tasks where the
22
- complexity of map-reduce may be unwarranted.
20
+ .. raw:: html
23
21
24
- Aggregation pipeline have some limitations on value types and result
25
- size. See :doc:`/core/aggregation-pipeline-limits` for details on
26
- limits and restrictions on the aggregation pipeline.
22
+ <video style="width:100%;" src="../../_images/agg-pipeline.mp4" controls> </video>
23
+
24
+ .. only:: website and html and (not dirhtml)
25
+
26
+ .. raw:: html
27
+
28
+ <video style="width:100%;" src="../_images/agg-pipeline.mp4" controls> </video>
29
+
30
+ In the example,
31
+
32
+ .. code-block:: javascript
33
+
34
+ db.orders.aggregate([
35
+ { $match: { status: "A" } },
36
+ { $group: { _id: "$cust_id", total: { $sum: "$amount" } } }
37
+ ])
38
+
39
+ **First Stage**: The :pipeline:`$match` stage filters the documents by
40
+ the ``status`` field and passes to the next stage those documents that
41
+ have ``status`` equal to ``"A"``.
42
+
43
+ **Second Stage**: The :pipeline:`$group` stage groups the documents by
44
+ the ``cust_id`` field to calculate the sum of the amount for each
45
+ unique ``cust_id``.
27
46
28
47
.. _aggregation-pipeline:
29
48
@@ -126,16 +145,36 @@ equivalent to a single query with a sort and can use an index. When
126
145
possible, place :pipeline:`$match` operators at the beginning of the
127
146
pipeline.
128
147
129
- Additional Features
130
- ~~~~~~~~~~~~~~~~~~~
148
+ Considerations
149
+ --------------
131
150
132
- The aggregation pipeline has an internal optimization phase that
133
- provides improved performance for certain sequences of operators. For
134
- details, see :doc:`/core/aggregation-pipeline-optimization`.
151
+ Sharded Collections
152
+ ~~~~~~~~~~~~~~~~~~~~
135
153
136
154
The aggregation pipeline supports operations on sharded collections.
137
155
See :ref:`aggregation-pipeline-sharded-collection`.
138
156
157
+ Aggregation vs Map-Reduce
158
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
159
+
160
+ The aggregation pipeline provides an alternative to :term:`map-reduce`
161
+ and may be the preferred solution for aggregation tasks where the
162
+ complexity of map-reduce may be unwarranted.
163
+
164
+ Limitations
165
+ ~~~~~~~~~~~
166
+
167
+ Aggregation pipeline have some limitations on value types and result
168
+ size. See :doc:`/core/aggregation-pipeline-limits` for details on
169
+ limits and restrictions on the aggregation pipeline.
170
+
171
+ Pipeline Optimization
172
+ ~~~~~~~~~~~~~~~~~~~~~
173
+
174
+ The aggregation pipeline has an internal optimization phase that
175
+ provides improved performance for certain sequences of operators. For
176
+ details, see :doc:`/core/aggregation-pipeline-optimization`.
177
+
139
178
.. toctree::
140
179
:titlesonly:
141
180
:hidden:
0 commit comments