Created
May 27, 2015 21:21
-
-
Save peterzawistowicz/99a927e343a734edddb3 to your computer and use it in GitHub Desktop.
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() { | |
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