Skip to content

Instantly share code, notes, and snippets.

@9b
Created March 24, 2011 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9b/885696 to your computer and use it in GitHub Desktop.
Save 9b/885696 to your computer and use it in GitHub Desktop.
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