Skip to content

Instantly share code, notes, and snippets.

@9b 9b/mr_named_funcs.js
Created Mar 24, 2011

Embed
What would you like to do?
Unique named functions with instance and total counts
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
You can’t perform that action at this time.