Skip to content

Instantly share code, notes, and snippets.

@jacqui
Created August 27, 2010 16:22
Show Gist options
  • Select an option

  • Save jacqui/553674 to your computer and use it in GitHub Desktop.

Select an option

Save jacqui/553674 to your computer and use it in GitHub Desktop.
> var map = function() { emit(this._id, { new_message_count : this.new_message_count }); };
> var reduce = function(key, values) {
... var new_message_sum = 0;
... values.forEach(function(doc) {
... new_message_sum += doc.new_message_count
... });
... return { stats: { new_message_count: new_message_sum } };
... };
> var op = db.mail_reader_stats.mapReduce(map, reduce);
> db[op.result].find();
{ "_id" : ObjectId("4c76a3753fe2262a83000001"), "value" : { "stats" : { "new_message_count" : 5 } } }
{ "_id" : ObjectId("4c76e62a3fe2260e03000001"), "value" : { "stats" : { "new_message_count" : 2 } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment