Skip to content

Commit 3f3317b

Browse files
committed
DOCS-686 mapreduce
1 parent 822c172 commit 3f3317b

File tree

7 files changed

+62
-83
lines changed

7 files changed

+62
-83
lines changed

source/applications.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ The following documents provide patterns for developing application features:
5151
.. toctree::
5252
:maxdepth: 2
5353

54+
tutorial/troubleshoot-map-reduce
5455
tutorial/perform-two-phase-commits
5556
tutorial/expire-data

source/applications/map-reduce.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ For more information on the parameters, see the
4646
:method:`db.collection.mapReduce()` reference page .
4747

4848
.. include:: /includes/examples-map-reduce.rst
49-
:start-after: map-reduce-examples-begin
50-
:end-before: map-reduce-sum-price-wrapper-end
51-
52-
.. include:: /includes/examples-map-reduce.rst
53-
:start-after: map-reduce-sum-price-cmd-end
54-
:end-before: map-reduce-item-counts-avg-wrapper-end
49+
:start-after: map-reduce-document-prototype-begin
5550

5651
.. _map-reduce-incremental:
5752

source/includes/examples-map-reduce.rst

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Map-Reduce Examples
22
-------------------
33

4-
.. map-reduce-examples-begin
4+
.. map-reduce-document-examples-begin
5+
.. map-reduce-document-prototype-begin
56
67
Consider the following map-reduce operations on a collection ``orders``
78
that contains documents of the following prototype:
@@ -19,11 +20,11 @@ that contains documents of the following prototype:
1920
}
2021
2122
.. map-reduce-document-prototype-end
22-
23+
2324
Sum the Price Per Customer Id
2425
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2526

26-
.. map-reduce-sum-price
27+
.. map-reduce-sum-price-begin
2728
2829
Perform map-reduce operation on the ``orders`` collection to group by
2930
the ``cust_id``, and for each ``cust_id``, calculate the sum of the
@@ -71,7 +72,6 @@ the ``cust_id``, and for each ``cust_id``, calculate the sum of the
7172
operation will replace the contents with the results of this
7273
map-reduce operation:
7374

74-
.. map-reduce-sum-price-wrapper-begin
7575
.. code-block:: javascript
7676
7777
db.orders.mapReduce(
@@ -80,24 +80,12 @@ the ``cust_id``, and for each ``cust_id``, calculate the sum of the
8080
{ out: "map_reduce_example" }
8181
)
8282
83-
.. map-reduce-sum-price-wrapper-end
84-
.. map-reduce-sum-price-cmd-begin
85-
.. code-block:: javascript
86-
87-
db.runCommand(
88-
{
89-
mapreduce: 'orders',
90-
map: mapFunction1,
91-
reduce: reduceFunction1,
92-
out: 'map_reduce_example'
93-
}
94-
)
95-
.. map-reduce-sum-price-cmd-end
83+
.. map-reduce-sum-price-end
9684
9785
Calculate the Number of Orders, Total Quantity, and Average Quantity Per Item
9886
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9987

100-
.. map-reduce-item-counts
88+
.. map-reduce-counts-begin
10189
10290
Perform map-reduce operation on the ``orders`` collection to group by
10391
the item sku, and for each sku, calculate the number of orders and the
@@ -178,8 +166,6 @@ greater than ``01/01/2012`` for the map-reduce:
178166
already exists, the operation will merge the existing contents with
179167
the results of this map-reduce operation:
180168

181-
.. map-reduce-item-counts-avg-end
182-
.. map-reduce-item-counts-avg-wrapper-begin
183169
.. code-block:: javascript
184170
185171
db.orders.mapReduce( mapFunction2,
@@ -191,21 +177,4 @@ greater than ``01/01/2012`` for the map-reduce:
191177
}
192178
)
193179
194-
.. map-reduce-item-counts-avg-wrapper-end
195-
.. map-reduce-item-counts-avg-cmd-begin
196-
.. code-block:: javascript
197-
198-
db.runCommand(
199-
{
200-
mapreduce: 'orders',
201-
map: mapFunction2,
202-
reduce: reduceFunction2,
203-
finalize: finalizeFunction2,
204-
out: { merge: "map_reduce_example" },
205-
query: { ord_date: { $gt: new Date('01/01/2012') } },
206-
}
207-
)
208-
209-
.. map-reduce-item-counts-avg-cmd-end
210-
211-
.. map-reduce-examples-end
180+
.. map-reduce-counts-end

source/reference/command/mapReduce.txt

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,50 @@ mapReduce
3030

3131
In addition to specifying the ``<collection>`` over which to perform
3232
the ``mapreduce`` command, the command accepts the following:
33-
33+
3434
.. include:: /includes/parameters-map-reduce.rst
3535

36+
A sample map-reduce operation using the :dbcommand:`mapReduce`
37+
command may have the following prototype:
38+
39+
.. code-block:: javascript
40+
41+
var mapFunction = function() { ... };
42+
var reduceFunction = function(key, values) { ... };
43+
44+
db.runCommand(
45+
{
46+
mapreduce: 'orders',
47+
map: mapFunction,
48+
reduce: reduceFunction,
49+
out: { merge: 'map_reduce_results' },
50+
query: { ord_date: { $gt: new Date('01/01/2012') } }
51+
}
52+
)
53+
54+
In the :program:`mongo`, the :method:`db.collection.mapReduce()`
55+
method is a wrapper around the :dbcommand:`mapReduce` command. The
56+
following examples use the :method:`db.collection.mapReduce()`:
57+
3658
.. include:: /includes/examples-map-reduce.rst
37-
:start-after: map-reduce-examples-begin
59+
:start-after: map-reduce-document-prototype-begin
3860
:end-before: map-reduce-document-prototype-end
3961

4062
- .. include:: /includes/examples-map-reduce.rst
41-
:start-after: map-reduce-sum-price
42-
:end-before: map-reduce-sum-price-wrapper-begin
63+
:start-after: map-reduce-sum-price-begin
64+
:end-before: map-reduce-sum-price-end
4365

44-
.. include:: /includes/examples-map-reduce.rst
45-
:start-after: map-reduce-sum-price-cmd-begin
46-
:end-before: map-reduce-sum-price-cmd-end
47-
4866
- .. include:: /includes/examples-map-reduce.rst
49-
:start-after: map-reduce-item-counts
50-
:end-before: map-reduce-item-counts-avg-end
67+
:start-after: map-reduce-counts-begin
68+
:end-before: map-reduce-counts-end
69+
70+
For more information and examples, see the :doc:`Map-Reduce
71+
</applications/map-reduce>` page.
5172

52-
.. include:: /includes/examples-map-reduce.rst
53-
:start-after: map-reduce-item-counts-avg-cmd-begin
54-
:end-before: map-reduce-item-counts-avg-cmd-end
73+
.. seealso::
5574

56-
.. seealso:: :method:`mapReduce()` and :term:`map-reduce`.
75+
- :term:`map-reduce` and :method:`db.collection.mapReduce()`
5776

58-
The :doc:`Map-Reduce </applications/map-reduce>`
59-
provides a greater overview of MongoDB's map-reduce
60-
functionality. Consider the :wiki:`Simple application
61-
<Aggregation>` support for basic aggregation operations as well
62-
as :doc:`/applications/aggregation`.
77+
- :doc:`/applications/aggregation`
6378

6479
.. slave-ok

source/reference/method/db.collection.mapReduce.txt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,23 @@ db.collection.mapReduce()
3030

3131
.. include:: /includes/parameters-map-reduce.rst
3232

33-
.. mapReduce-syntax-end
34-
3533
.. include:: /includes/examples-map-reduce.rst
36-
:start-after: map-reduce-examples-begin
34+
:start-after: map-reduce-document-prototype-begin
3735
:end-before: map-reduce-document-prototype-end
3836

3937
- .. include:: /includes/examples-map-reduce.rst
40-
:start-after: map-reduce-sum-price
41-
:end-before: map-reduce-sum-price-wrapper-end
38+
:start-after: map-reduce-sum-price-begin
39+
:end-before: map-reduce-sum-price-end
4240

4341
- .. include:: /includes/examples-map-reduce.rst
44-
:start-after: map-reduce-item-counts
45-
:end-before: map-reduce-item-counts-avg-wrapper-end
46-
47-
.. seealso:: :term:`map-reduce` and :dbcommand:`mapReduce`
42+
:start-after: map-reduce-counts-begin
43+
:end-before: map-reduce-counts-end
4844

49-
The :doc:`Map-Reduce </applications/map-reduce>` page
50-
provides a greater overview of MongoDB's map-reduce
51-
functionality, while the :doc:`/applications/aggregation`
52-
provides an overview of the aggregation framework.
45+
For more information and examples, see the :doc:`Map-Reduce
46+
</applications/map-reduce>` page.
5347

54-
.. Consider
55-
.. STUB ":doc:`/applications/simple-aggregation` for simple aggregation
56-
.. operations and :doc:`/applications/aggregation`" for a more flexible
57-
.. approach to data aggregation in MongoDB.
48+
.. seealso::
49+
50+
- :term:`map-reduce` and :dbcommand:`mapReduce`
51+
52+
- :doc:`/applications/aggregation`

source/tutorial.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Application Development
5151
.. toctree::
5252
:maxdepth: 1
5353

54+
tutorial/troubleshoot-map-reduce
5455
tutorial/write-a-tumblelog-application-with-django-mongodb-engine
5556
tutorial/write-a-tumblelog-application-with-flask-mongoengine
5657

source/tutorial/troubleshoot-map-reduce.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ Troubleshoot Map-Reduce
44

55
.. default-domain:: mongodb
66

7+
The :doc:`/applications/map-reduce` operation requires both the ``map``
8+
function and the ``reduce`` function.
9+
710
You can troubleshoot the ``map`` function and the ``reduce`` function
8-
in the :program:`mongo` shell.
11+
in the :program:`mongo` shell.
912

1013
.. _troubleshoot-map-function:
1114

@@ -258,7 +261,7 @@ should equal the same as if all the values were passed in one call.
258261
];
259262

260263
#. Define a sample ``values1`` array that combines the values passed to
261-
``reduceFunction2``:
264+
``reduceFunction2``:
262265

263266
.. code-block:: javascript
264267

@@ -269,7 +272,7 @@ should equal the same as if all the values were passed in one call.
269272
];
270273

271274
#. Invoke the ``reduceFunction2`` first with ``myKey`` and
272-
``valuesIdempotent`` and then with ``myKey`` and ``values1``:
275+
``valuesIdempotent`` and then with ``myKey`` and ``values1``:
273276

274277
.. code-block:: javascript
275278

0 commit comments

Comments
 (0)