Skip to content

Instantly share code, notes, and snippets.

@thinkloop
Created August 19, 2014 13:12
Show Gist options
  • Save thinkloop/0b94dd1db74f704caa13 to your computer and use it in GitHub Desktop.
Save thinkloop/0b94dd1db74f704caa13 to your computer and use it in GitHub Desktop.
MapReduceRatings
MAP:
function(doc) {
emit(doc.itemID, doc);
}
REDUCE:
function(keys, values, rereduce){
var i,
accounts = [];
if (!rereduce){
for (i = 0; i < values.length; i++) {
accounts.push({ accountID: values[i].accountID, rating: values[i] });
}
}
else {
for (i = 0; i < values.length; i++) {
accounts = accounts.concat(values[i]);
}
}
return accounts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment