Skip to content

Commit 029c076

Browse files
jason-price-mongodbandf-mongodb
authored andcommitted
DOCS-14048 mapReduce refactoring
1 parent c8dfefb commit 029c076

18 files changed

+145
-204
lines changed

source/aggregation.txt

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ transforms the documents into an aggregated result. For example:
4141

4242
<video style="width:100%;" src="_images/agg-pipeline.mp4" controls> </video>
4343

44-
In the example,
44+
In the example:
4545

4646
.. code-block:: javascript
4747

@@ -82,28 +82,6 @@ internal optimization phase. See
8282
:ref:`aggregation-pipeline-operators-and-performance` and
8383
:doc:`/core/aggregation-pipeline-optimization` for details.
8484

85-
.. _aggregation-map-reduce:
86-
87-
Map-Reduce
88-
----------
89-
90-
.. tip::
91-
92-
:doc:`Aggregation pipeline </core/aggregation-pipeline>`
93-
provides better performance and a more coherent interface than
94-
map-reduce.
95-
96-
For examples of aggregation alternatives to map-reduce operations,
97-
see :doc:`/tutorial/map-reduce-examples`. See also
98-
:doc:`/reference/map-reduce-to-aggregation-pipeline`.
99-
100-
MongoDB also provides :doc:`map-reduce </core/map-reduce>` operations
101-
to perform aggregation. Map-reduce uses custom JavaScript functions to
102-
perform the map and reduce operations, as well as the optional
103-
*finalize* operation.
104-
105-
.. include:: /images/map-reduce.rst
106-
10785
.. _single-purpose-agg-operations:
10886

10987
Single Purpose Aggregation Operations
@@ -114,11 +92,18 @@ MongoDB also provides :method:`db.collection.estimatedDocumentCount()`,
11492

11593
All of these operations aggregate documents from a single collection.
11694
While these operations provide simple access to common aggregation
117-
processes, they lack the flexibility and capabilities of the
118-
aggregation pipeline and map-reduce.
95+
processes, they lack the flexibility and capabilities of an aggregation
96+
pipeline.
11997

12098
.. include:: /images/distinct.rst
12199

100+
.. _aggregation-map-reduce:
101+
102+
Map-Reduce
103+
----------
104+
105+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
106+
122107
Additional Features and Behaviors
123108
---------------------------------
124109

source/core/aggregation-pipeline.txt

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ results. For example:
2929

3030
<video style="width:100%;" src="../_images/agg-pipeline.mp4" controls> </video>
3131

32-
In the example,
32+
In the example:
3333

3434
.. code-block:: javascript
3535

@@ -53,8 +53,8 @@ Pipeline
5353

5454
The MongoDB aggregation pipeline consists of :ref:`stages
5555
<aggregation-pipeline-operator-reference>`. Each stage transforms the
56-
documents as they pass through the pipeline. Pipeline stages do not
57-
need to produce one output document for every input document; e.g.,
56+
documents as they pass through the pipeline. Pipeline stages do not need
57+
to produce one output document for every input document. For example,
5858
some stages may generate new documents or filter out documents.
5959

6060
Pipeline stages can appear multiple times in the pipeline with the
@@ -98,11 +98,11 @@ by the aggregation process with one exception: :ref:`accumulator
9898
<aggregation-accumulator-operators>` expressions.
9999

100100
The accumulators, used in the :pipeline:`$group` stage, maintain their
101-
state (e.g. totals, maximums, minimums, and related data) as documents
102-
progress through the pipeline. Some accumulators are available in the
103-
:pipeline:`$project` stage; however, when used in the
104-
:pipeline:`$project` stage, the accumulators do not maintain their
105-
state across documents.
101+
state (for example, totals, maximums, minimums, and related data) as
102+
documents progress through the pipeline. Some accumulators are available
103+
in the :pipeline:`$project` stage; however, when used in the
104+
:pipeline:`$project` stage, the accumulators do not maintain their state
105+
across documents.
106106

107107
Starting in version 4.4, MongoDB provides the :group:`$accumulator` and
108108
:expression:`$function` aggregation operators. These operators provide
@@ -194,41 +194,29 @@ pipeline.
194194
Considerations
195195
--------------
196196

197-
Sharded Collections
198-
~~~~~~~~~~~~~~~~~~~~
197+
Aggregation Pipeline Limitations
198+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
199199

200-
The aggregation pipeline supports operations on sharded collections.
201-
See :ref:`aggregation-pipeline-sharded-collection`.
202-
203-
Aggregation Pipeline vs Map-Reduce
204-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200+
An aggregation pipeline has some limitations on the value types and
201+
the result size. See :doc:`/core/aggregation-pipeline-limits`.
205202

206-
The aggregation pipeline provides better performance and a more coherent
207-
interface than :doc:`map-reduce </core/map-reduce>`.
203+
Aggregation Pipeline Optimization
204+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
208205

209-
Various map-reduce operations can be rewritten using :doc:`aggregation
210-
pipeline operators </meta/aggregation-quick-reference>`, such as
211-
:pipeline:`$group`, :pipeline:`$merge`, etc. For map-reduce operations
212-
that require custom functionality, MongoDB provides the
213-
:group:`$accumulator` and :expression:`$function` aggregation operators
214-
starting in version 4.4. These operators provide users with the ability
215-
to define custom aggregation expressions in JavaScript.
206+
An aggregation pipeline has an internal optimization phase that provides
207+
improved performance for certain sequences of operators. See
208+
:doc:`/core/aggregation-pipeline-optimization`.
216209

217-
See :doc:`/tutorial/map-reduce-examples` for details.
218-
219-
Limitations
220-
~~~~~~~~~~~
210+
Aggregation on Sharded Collections
211+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221212

222-
Aggregation pipeline have some limitations on value types and result
223-
size. See :doc:`/core/aggregation-pipeline-limits` for details on
224-
limits and restrictions on the aggregation pipeline.
213+
An aggregation pipeline supports operations on sharded collections.
214+
See :ref:`aggregation-pipeline-sharded-collection`.
225215

226-
Pipeline Optimization
227-
~~~~~~~~~~~~~~~~~~~~~
216+
Aggregation Pipeline as an Alternative to Map-Reduce
217+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228218

229-
The aggregation pipeline has an internal optimization phase that
230-
provides improved performance for certain sequences of operators. For
231-
details, see :doc:`/core/aggregation-pipeline-optimization`.
219+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
232220

233221
.. toctree::
234222
:titlesonly:

source/core/map-reduce-concurrency.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Map-Reduce Concurrency
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. admonition:: Aggregation Pipeline as an Alternative to Map-Reduce
14+
:class: note
15+
16+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
17+
1318
The map-reduce operation is composed of many tasks, including reads
1419
from the input collection, executions of the ``map`` function,
1520
executions of the ``reduce`` function, writes to a temporary collection

source/core/map-reduce-sharded-collections.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Map-Reduce and Sharded Collections
1010
:depth: 1
1111
:class: singlecol
1212

13+
.. admonition:: Aggregation Pipeline as an Alternative to Map-Reduce
14+
:class: note
15+
16+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
17+
1318
Map-reduce supports operations on sharded collections, both as an input
1419
and as an output. This section describes the behaviors of
1520
:dbcommand:`mapReduce` specific to sharded collections.

source/core/map-reduce.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,10 @@ Map-Reduce
1010
:depth: 1
1111
:class: singlecol
1212

13-
.. admonition:: Aggregation Pipeline as Alternative
13+
.. admonition:: Aggregation Pipeline as Alternative to Map-Reduce
1414
:class: note
1515

16-
:doc:`Aggregation pipeline </core/aggregation-pipeline>`
17-
provides better performance and a more coherent interface than
18-
map-reduce, and various map-reduce operations can be rewritten
19-
using :doc:`aggregation pipeline operators
20-
</meta/aggregation-quick-reference>`, such as :pipeline:`$group`,
21-
:pipeline:`$merge`, :group:`$accumulator`, etc.
22-
23-
For examples of aggregation alternatives to map-reduce operations,
24-
see :doc:`/tutorial/map-reduce-examples`. See also
25-
:doc:`/reference/map-reduce-to-aggregation-pipeline`.
16+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
2617

2718
Map-reduce is a data processing paradigm for condensing large volumes
2819
of data into useful *aggregated* results. To perform map-reduce

source/includes/examples-map-reduce.rst

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,10 @@ Map-Reduce Examples
44
.. map-reduce-document-examples-begin
55
.. map-reduce-document-prototype-begin
66
7-
.. admonition:: Aggregation Pipeline as Alternative
8-
:class: note
9-
10-
:doc:`Aggregation pipeline </core/aggregation-pipeline>` provides
11-
better performance and a simpler interface than map-reduce, and
12-
map-reduce expressions can be rewritten using :doc:`aggregation
13-
pipeline operators </meta/aggregation-quick-reference>` such as
14-
:pipeline:`$group`, :pipeline:`$merge`, and others.
15-
16-
For map-reduce expressions that require custom functionality, MongoDB
17-
provides the :group:`$accumulator` and :expression:`$function`
18-
aggregation operators starting in version 4.4. These operators
19-
provide the ability to define custom aggregation expressions in
20-
JavaScript.
21-
22-
The examples in this section include aggregation pipeline
23-
alternatives without custom aggregation expressions. For alternatives
24-
that use custom expressions, see :ref:`Map-Reduce to Aggregation
25-
Pipeline Translation Examples <mr-to-agg-examples>`.
7+
The examples in this section include aggregation pipeline alternatives
8+
without custom aggregation expressions. For alternatives that use custom
9+
expressions, see :ref:`Map-Reduce to Aggregation Pipeline Translation
10+
Examples <mr-to-agg-examples>`.
2611

2712
Create a sample collection ``orders`` with these documents:
2813

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
An :doc:`aggregation pipeline </core/aggregation-pipeline>` provides
2+
better performance and usability than a :doc:`map-reduce
3+
</core/map-reduce>` operation.
4+
5+
Map-reduce operations can be rewritten using :doc:`aggregation pipeline
6+
operators </meta/aggregation-quick-reference>`, such as
7+
:pipeline:`$group`, :pipeline:`$merge`, and others.
8+
9+
For map-reduce operations that require custom functionality, MongoDB
10+
provides the :group:`$accumulator` and :expression:`$function`
11+
aggregation operators starting in version 4.4. Use these operators to
12+
define custom aggregation expressions in JavaScript.
13+
14+
For examples of aggregation pipeline alternatives to map-reduce
15+
operations, see :doc:`/reference/map-reduce-to-aggregation-pipeline` and
16+
:doc:`/tutorial/map-reduce-examples`.

source/reference/aggregation-commands-comparison.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,10 @@ Aggregation Commands Comparison
1010
:depth: 1
1111
:class: singlecol
1212

13-
.. tip::
13+
.. admonition:: Aggregation Pipeline as Alternative to Map-Reduce
14+
:class: note
1415

15-
Starting in version 4.4, MongoDB adds the :group:`$accumulator` and
16-
:expression:`$function` aggregation operators. Using
17-
:group:`$accumulator` and :expression:`$function` ,
18-
:dbcommand:`mapReduce` expressions can be re-written using the
19-
aggregation operators.
20-
21-
Even before version 4.4, some map-reduce expressions could also be
22-
rewritten using :doc:`other aggregation pipeline operators
23-
</meta/aggregation-quick-reference>`, such as :pipeline:`$group`,
24-
:pipeline:`$merge`, etc.
16+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
2517

2618
Aggregation Commands Comparison Table
2719
-------------------------------------
@@ -47,7 +39,7 @@ MongoDB aggregation commands.
4739

4840
Uses a "pipeline" approach where objects are transformed as they
4941
pass through a series of pipeline operators such as
50-
:pipeline:`$group`, :pipeline:`$match`, and :pipeline:`$sort`.
42+
:pipeline:`$group`, :pipeline:`$match`, and :pipeline:`$sort`.
5143

5244
See :doc:`/reference/operator/aggregation` for more information
5345
on the pipeline operators.

source/reference/command/mapReduce.txt

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ mapReduce
1010
:depth: 1
1111
:class: singlecol
1212

13-
.. admonition:: Deprecated
14-
:class: warning
13+
.. admonition:: Aggregation Pipeline as Alternative to Map-Reduce
14+
:class: note
1515

16-
.. include:: /includes/5.0-mapReduce-deprecated.rst
16+
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
1717

1818
Definition
1919
----------
@@ -22,26 +22,6 @@ Definition
2222

2323
The :dbcommand:`mapReduce` command allows you to run
2424
:term:`map-reduce` aggregation operations over a collection.
25-
26-
.. admonition:: Aggregation Pipeline as Alternative
27-
:class: note
28-
29-
:doc:`Aggregation pipeline </core/aggregation-pipeline>`
30-
provides better performance and a simpler interface than
31-
map-reduce, and map-reduce expressions can be
32-
rewritten using :doc:`aggregation pipeline operators
33-
</meta/aggregation-quick-reference>`, such as :pipeline:`$group`,
34-
:pipeline:`$merge`, and so on.
35-
36-
For map-reduce expressions that require custom functionality,
37-
MongoDB provides the :group:`$accumulator` and
38-
:expression:`$function` aggregation operators starting in version
39-
4.4. These operators provide users with the ability to define custom
40-
aggregation expressions in JavaScript.
41-
42-
For examples of aggregation alternatives to map-reduce operations,
43-
see :doc:`/tutorial/map-reduce-examples`. See also
44-
:doc:`/reference/map-reduce-to-aggregation-pipeline`.
4525

4626
Syntax
4727
------

source/reference/map-reduce-to-aggregation-pipeline.txt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ Map-Reduce to Aggregation Pipeline
44

55
.. default-domain:: mongodb
66

7-
Starting in version 4.4, MongoDB adds the :group:`$accumulator` and
8-
:expression:`$function` aggregation operators. These operators provide
9-
users the ability to define custom aggregation expressions. Using these
10-
operations, the map-reduce expressions can be approximately re-written
11-
as in the following table.
7+
An :doc:`aggregation pipeline </core/aggregation-pipeline>` provides
8+
better performance and usability than a :doc:`map-reduce
9+
</core/map-reduce>` operation.
1210

13-
.. note::
11+
Map-reduce operations can be rewritten using :doc:`aggregation pipeline
12+
operators </meta/aggregation-quick-reference>`, such as
13+
:pipeline:`$group`, :pipeline:`$merge`, and others.
1414

15-
Various map-reduce expressions can be rewritten using
16-
:doc:`aggregation pipeline operators
17-
</meta/aggregation-quick-reference>`, such as :pipeline:`$group`,
18-
:pipeline:`$merge`, etc., without requiring custom functions.
15+
For map-reduce operations that require custom functionality, MongoDB
16+
provides the :group:`$accumulator` and :expression:`$function`
17+
aggregation operators starting in version 4.4. Use these operators to
18+
define custom aggregation expressions in JavaScript.
1919

20-
For examples, see :doc:`/tutorial/map-reduce-examples`.
20+
Map-reduce expressions can be re-written as shown in the following
21+
sections.
2122

2223
Map-Reduce to Aggregation Pipeline Translation Table
2324
----------------------------------------------------
@@ -250,9 +251,9 @@ Examples
250251

251252
Various map-reduce expressions can be rewritten using :doc:`aggregation
252253
pipeline operators </meta/aggregation-quick-reference>`, such as
253-
:pipeline:`$group`, :pipeline:`$merge`, etc., without requiring custom
254-
functions. However, for illustrative purposes, the following examples
255-
provide both alternatives.
254+
:pipeline:`$group`, :pipeline:`$merge`, and others, without requiring
255+
custom functions. However, for illustrative purposes, the following
256+
examples provide both alternatives.
256257

257258
.. _mr-to-agg-examples1:
258259

0 commit comments

Comments
 (0)