Databases Reference
In-Depth Information
MongoDB and MapReduce
Both of the previous examples used only the mapreduce , map , and reduce keys. These
three keys are required, but there are many optional keys that can be passed to the
MapReduce command.
"finalize" : function
A final step to send reduce 's output to.
"keeptemp" : boolean
If the temporary result collection should be saved when the connection is closed.
"output" : string
Name for the output collection. Setting this option implies keeptemp : true .
"query" : document
Query to filter documents by before sending to the map function.
"sort" : document
Sort to use on documents before sending to the map (useful in conjunction with
the limit option).
"limit" : integer
Maximum number of documents to send to the map function.
"scope" : document
Variables that can be used in any of the JavaScript code.
"verbose" : boolean
Whether to use more verbose output in the server logs.
The finalize function
As with the previous group command, MapReduce can be passed a finalize function
that will be run on the last reduce 's output before it is saved to a temporary collection.
Returning large result sets is less critical with MapReduce than group , because the whole
result doesn't have to fit in 4MB. However, the information will be passed over the wire
eventually, so finalize is a good chance to take averages, chomp arrays, and remove
extra information in general.
Keeping output collections
By default, Mongo creates a temporary collection while it is processing the MapReduce
with a name that you are unlikely to choose for a collection: a dot-separated string
containing mr , the name of the collection you're MapReducing, a timestamp, and the
job's ID with the database. It ends up looking something like mr.stuff.
18234210220.2 . MongoDB will automatically destroy this collection when the con-
nection that did the MapReduce is closed. (You can also drop it manually when you're
done with it.) If you want to persist this collection even after disconnecting, you can
specify keeptemp : true as an option.
 
Search WWH ::




Custom Search