Created
August 27, 2010 16:22
-
-
Save jacqui/553674 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > 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