LearnBoost/mongoose — Issue #678: Documenting MapReduce
Author: fzaninotto
Created: 2012-01-11 11:34:55+00:00
State: open

I found no documentation on the MapReduce feature. Just point me to the right place to do so, and I'm willing to share my experience in a PR. I could do this in docs/query.md, but since the mapReduce method is in the collection subobject (which is not documented), I don't know where to start.

A simple example is a good start, here is what could bootstrap this doc:

```js
var Foo = new Schema({
type: : String
, date : { type: Date, default: Date.now }
, value : Number
});

Foo.statics.countValueForDate = function(start, end, callback) {
var mapFunction = function() {
emit(this.type, { count: this.check } )
}
var reduceFunction = function(key, values) {
var result = { count: 0 };
values.forEach(function(value) {
result.count += value.count;
});
return result;
}
this.collection.mapReduce(
mapFunction.toString(),
reduceFunction.toString(),
{ query: { date: { $gte: start }, date: { $lte: end } }, out: { inline: 1 } },
callback
);
}
```