1
1
Map-Reduce Examples
2
2
-------------------
3
3
4
- .. map-reduce-examples-begin
4
+ .. map-reduce-document-examples-begin
5
+ .. map-reduce-document-prototype-begin
5
6
6
7
Consider the following map-reduce operations on a collection ``orders ``
7
8
that contains documents of the following prototype:
@@ -19,11 +20,11 @@ that contains documents of the following prototype:
19
20
}
20
21
21
22
.. map-reduce-document-prototype-end
22
-
23
+
23
24
Sum the Price Per Customer Id
24
25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26
26
- .. map-reduce-sum-price
27
+ .. map-reduce-sum-price-begin
27
28
28
29
Perform map-reduce operation on the ``orders `` collection to group by
29
30
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
71
72
operation will replace the contents with the results of this
72
73
map-reduce operation:
73
74
74
- .. map-reduce-sum-price-wrapper-begin
75
75
.. code-block :: javascript
76
76
77
77
db .orders .mapReduce (
@@ -80,24 +80,12 @@ the ``cust_id``, and for each ``cust_id``, calculate the sum of the
80
80
{ out: " map_reduce_example" }
81
81
)
82
82
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
96
84
97
85
Calculate the Number of Orders, Total Quantity, and Average Quantity Per Item
98
86
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
87
100
- .. map-reduce-item- counts
88
+ .. map-reduce-counts-begin
101
89
102
90
Perform map-reduce operation on the ``orders `` collection to group by
103
91
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:
178
166
already exists, the operation will merge the existing contents with
179
167
the results of this map-reduce operation:
180
168
181
- .. map-reduce-item-counts-avg-end
182
- .. map-reduce-item-counts-avg-wrapper-begin
183
169
.. code-block :: javascript
184
170
185
171
db .orders .mapReduce ( mapFunction2,
@@ -191,21 +177,4 @@ greater than ``01/01/2012`` for the map-reduce:
191
177
}
192
178
)
193
179
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
0 commit comments