-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathmapReduce.txt
More file actions
82 lines (62 loc) · 2.55 KB
/
mapReduce.txt
File metadata and controls
82 lines (62 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
=========
mapReduce
=========
.. default-domain:: mongodb
.. dbcommand:: mapReduce
The :dbcommand:`mapReduce` command allows you to run
:term:`map-reduce` aggregation operations over a collection. The
:dbcommand:`mapReduce` command has the following prototype
form:
.. code-block:: javascript
db.runCommand(
{
mapReduce: <collection>,
map: <function>,
reduce: <function>,
out: <collection>,
query: <document>,
sort: <document>,
limit: <number>,
finalize: <function>,
scope: <document>,
jsMode: <boolean>,
verbose: <boolean>
}
)
Pass the name of the collection to the ``mapReduce`` command
(i.e. ``<collection>``) to use as the source documents to perform
the map reduce operation. The command also accepts the following
parameters:
.. include:: /includes/parameters-map-reduce.rst
Consider the following prototype map:dbcommand:`mapReduce`
operation:
.. code-block:: javascript
var mapFunction = function() { ... };
var reduceFunction = function(key, values) { ... };
db.runCommand(
{
mapReduce: 'orders',
map: mapFunction,
reduce: reduceFunction,
out: { merge: 'map_reduce_results' },
query: { ord_date: { $gt: new Date('01/01/2012') } }
}
)
In the :program:`mongo`, the :method:`db.collection.mapReduce()`
method is a wrapper around the :dbcommand:`mapReduce` command. The
following examples use the :method:`db.collection.mapReduce()`:
.. include:: /includes/examples-map-reduce.rst
:start-after: map-reduce-document-prototype-begin
:end-before: map-reduce-document-prototype-end
- .. include:: /includes/examples-map-reduce.rst
:start-after: map-reduce-sum-price-begin
:end-before: map-reduce-sum-price-end
- .. include:: /includes/examples-map-reduce.rst
:start-after: map-reduce-counts-begin
:end-before: map-reduce-counts-end
For more information and examples, see the :doc:`Map-Reduce
</applications/map-reduce>` page.
.. seealso::
- :term:`map-reduce` and :method:`db.collection.mapReduce()`
- :doc:`/applications/aggregation`
.. slave-ok