Skip to content

Instantly share code, notes, and snippets.

@peterzawistowicz
Created May 27, 2015 21:21
Show Gist options
  • Save peterzawistowicz/99a927e343a734edddb3 to your computer and use it in GitHub Desktop.
Save peterzawistowicz/99a927e343a734edddb3 to your computer and use it in GitHub Desktop.
var map = function() {
for (i = 0; i < this.items.length; i++) {
for (j = i + 1; j <= this.items.length; j++) {
emit({a: this.items[i] ,b: this.items[j] }, 1); // emit each item pair
}
}
}
var reduce = function(key, values)
{ return Array.sum(values); } // Sum all occurrences of each item pair
db.lastDayOrders.mapReduce(map, reduce,
{out: { replace: "pairs", sharded: true }) // persist the output to a collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment