11Map-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 ``
78that 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
2930the ``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
10391the 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
0 commit comments