@@ -10,18 +10,18 @@ Overview
1010--------
1111
1212The MongoDB aggregation framework provides a means to calculate
13- aggregate values without having to use :term:`map-reduce`. While
14- map-reduce is powerful, using map-reduce is more difficult than
13+ aggregated values without having to use :term:`map-reduce`. While
14+ map-reduce is powerful, it is often more difficult than
1515necessary for many simple aggregation tasks, such as totaling or
1616averaging field values.
1717
1818If you're familiar with :term:`SQL`, the aggregation framework
1919provides similar functionality to ``GROUP BY`` and related SQL
2020operators as well as simple forms of "self joins." Additionally, the
21- aggregation framework provides projection capabilities to resultshape the
22- returned data. Using projections and aggregation, you can add computed
23- fields, create new virtual sub-objects, and extract sub-fields into
24- the top-level of results.
21+ aggregation framework provides projection capabilities to reshape the
22+ returned data. Using the projections in the aggregation framework , you
23+ can add computed fields, create new virtual sub-objects, and extract
24+ sub-fields into the top-level of results.
2525
2626.. seealso:: A presentation from MongoSV 2011: `MongoDB's New
2727 Aggregation Framework <http://www.10gen.com/presentations/mongosv-2011/mongodbs-new-aggregation-framework>`_
@@ -74,28 +74,24 @@ through the pipeline.
7474 - :agg:pipeline:`$group`
7575 - :agg:pipeline:`$sort`
7676
77- .. - :agg:pipeline:`$out`
78-
7977.. _aggregation-expressions:
8078
8179Expressions
8280~~~~~~~~~~~
8381
84- Expressions calculate values from documents as they pass through the
85- pipeline and collect these results with calculated values from the
86- other documents that have flowed through the pipeline. The
87- aggregation framework defines expressions in a :term:`JSON` like format using
88- prefixes.
82+ :ref:`Expressions <aggregation-expression-operators>` produce output
83+ document based on calculations performed on input documents. The
84+ aggregation framework defines expressions using a document format
85+ using prefixes.
8986
90- Often, expressions are stateless and are only evaluated when seen by
91- the aggregation process. Stateless expressions perform operations such
92- as adding the values of two fields together or extracting the year
93- from a date .
87+ Expressions are stateless and are only evaluated when seen by the
88+ aggregation process. All aggregation expressions can only operate on
89+ the current document, in the pipeline, and cannot integrate data from
90+ other documents .
9491
95- The :term:`accumulator` expressions *do* retain state, and the
96- :agg:pipeline:`$group` operator maintains that state (e.g.
97- totals, maximums, minimums, and related data.) as documents progress
98- through the :term:`pipeline`.
92+ The :term:`accumulator` expressions used in the :agg:pipeline:`$group`
93+ operator maintain that state (e.g. totals, maximums, minimums, and
94+ related data) as documents progress through the :term:`pipeline`.
9995
10096.. seealso:: :ref:`Aggregation expressions
10197 <aggregation-expression-operators>` for additional examples of the
@@ -107,17 +103,15 @@ Use
107103Invocation
108104~~~~~~~~~~
109105
110- Invoke an :term:`aggregation` operation with the :func:`aggregate`
106+ Invoke an :term:`aggregation` operation with the :func:`aggregate() <db.collection.aggregate()> `
111107wrapper in the :program:`mongo` shell or the :dbcommand:`aggregate`
112- :term:`database command`. Always call :func:`aggregate` on a
113- collection object, which will determine the documents that contribute
114- to the beginning of the aggregation :term:`pipeline`. The arguments to
115- the :func:`aggregate` function specifies a sequence of :ref:`pipeline
108+ :term:`database command`. Always call :func:`aggregate() <db.collection.aggregate()>` on a
109+ collection object that determines the input documents to the aggregation :term:`pipeline`.
110+ The arguments to the :func:`aggregate() <db.collection.aggregate()>` function specifies a sequence of :ref:`pipeline
116111operators <aggregation-pipeline-operator-reference>`, where each
117- :ref:`pipeline operator <aggregation-pipeline-operator-reference>` may
118- have a number of operands.
112+ operator may have a number of operands.
119113
120- First, consider a :term:`collection` of documents named ``article ``
114+ First, consider a :term:`collection` of documents named ``articles ``
121115using the following format:
122116
123117.. code-block:: javascript
@@ -142,7 +136,7 @@ command:
142136
143137.. code-block:: javascript
144138
145- db.article .aggregate(
139+ db.articles .aggregate(
146140 { $project : {
147141 author : 1,
148142 tags : 1,
@@ -154,12 +148,12 @@ command:
154148 } }
155149 );
156150
157- This operation uses the :func:`aggregate` wrapper around the
158- :term:`database command` :dbcommand:`aggregate`. The aggregation
159- pipleine begins with the :term:`collection` ``article`` and selects
160- the ``author`` and ``tags`` fields using the :agg:pipeline:`$project`
161- aggregation operator, and runs the :agg:expression:`$unwind` and
162- :agg:expression:`$group` on these fields to pivot the data.
151+ The aggregation pipeline begins with the :term:`collection`
152+ ``article`` and selects the ``author`` and ``tags`` fields using the
153+ :agg:pipeline:`$project` aggregation operator, and runs the
154+ :agg:expression:`$unwind` operator to produce one output document per
155+ tag finally uses the :agg:expression:`$group` operator on these fields
156+ to pivot the data.
163157
164158Result
165159~~~~~~
@@ -173,13 +167,7 @@ The aggregation operation in the previous section returns a
173167 if there was an error
174168
175169As a document, the result is subject to the current :ref:`BSON
176- Document size <limit-bson-document-size>`.
177-
178- .. OMMITED: as $out will not be available in 2.2
179- ..
180- .. If you expect the aggregation framework to return a larger result,
181- .. consider using the use the :agg:pipeline:`$out` pipeline operator to
182- .. write the output to a collection.
170+ Document size <limit-bson-document-size>`, which is 16 megabytes.
183171
184172Optimizing Performance
185173----------------------
0 commit comments