Map/reduce in MongoDB is useful for batch processing of
data and aggregation operations. It is similar in spirit to using
something like Hadoop with all input coming from a collection and output
going to a collection. Often, in a situation where you would have used
GROUP BY in SQL, map/reduce is the right tool in MongoDB.
[table]
Indexing
and standard queries in MongoDB are separate from map/reduce. If you
have used CouchDB in the past, note this is a big difference: MongoDB is
more like MySQL for basic querying and indexing. See the queries and indexing documentation for those operations.
Overview
Output options
Result object
Map Function
Reduce Function
Finalize Function
Sharded Environments
Examples
Shell Example 1
Shell Example 2
More Examples
Note on Permanent Collections
Parallelism
Presentations
See Also
Overview
map/reduce is invoked via a database command.
The database creates a temporary collection to hold output of the
operation. The collection is cleaned up when the client connection
closes, or when explicitly dropped. Alternatively, one can specify a
permanent output collection name. map and reduce functions are written in JavaScript and execute on the server.
Command syntax:
* keeptemp - if true, the generated collection is not treated as temporary. Defaults to false. When out is specified, the collection is automatically made permanent. (MongoDB