Skip to content

Instantly share code, notes, and snippets.

@9b
Created March 24, 2011 19:39
Show Gist options
  • Save 9b/885707 to your computer and use it in GitHub Desktop.
Save 9b/885707 to your computer and use it in GitHub Desktop.
Component totals and averages for a PDF set
var map = function () {
this.structure.components.component.forEach(
function (z) {
emit(z.name, {count: 0, total: z.count, avg:0});
}
);
}
var reduce = function (key, values) {
var count = db.malware.count();
var total = 0;
for (var i = 0; i < values.length; i++) {
total += values[i].total;
}
avg = total/count;
return { count: count, avg: avg, total: total};
}
db.malware.mapReduce(map,reduce, {out: "component_totals" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment