Created
March 24, 2011 19:37
-
-
Save 9b/885696 to your computer and use it in GitHub Desktop.
Unique named functions with instance and total counts
This file contains 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 () { | |
this.structure.keywords.keyword.forEach( | |
function (z) { | |
emit(z.name, {count_sum: z.count, count: 1}); | |
} | |
); | |
} | |
var reduce = function (key, values) { | |
var total = 0; | |
var count = 0; | |
var stotal = 0; | |
for (var i = 0; i < values.length; i++) { | |
stotal += values[i].count; | |
total += values[i].count_sum; | |
count++; | |
} | |
return { count_sum:total, count: stotal }; | |
} | |
db.malware.mapReduce(map,reduce, {out: "named_funcs" }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment