mongodb/node-mongodb-native — pull request #598 by sakno (2012-05-04 04:52:03+00:00)
Title: Cursor-level mapReduce

Cursor-level mapReduce function allows to process cursor as array without loading the result set into the memory. This function differs from `mapReduce` provided by Mongo because it is running on client-side. The following example demonstrates this new feature:

```js
client.collection('customers', function(err, collection){ //for each document from the cursor
collection.find().mapReduce(function(cust, report, next){
report.push({firstName: cust.firstName, lastName: cust.lastName}); //modify initial document
next(); //moves to the next document from the cursor
},
new Array(), //initial document
function(report){ //this function will be called once when cursor returns all elements
console.log('Customers: %j', report);
});
});
```
`mapReduce` function will be called at client-side and doesn't use native MongoDB-native mapReduce. It uses `nextObject` function as well as `each` and `toArray` functions.