Skip to content

Instantly share code, notes, and snippets.

@bluescreen303
Created August 30, 2009 16:28
Show Gist options
  • Save bluescreen303/178034 to your computer and use it in GitHub Desktop.
Save bluescreen303/178034 to your computer and use it in GitHub Desktop.
// map function
function(op) {
if(op.channel) {
emit(op.channel, op);
}
}
// reduce
function(keys, ops, rereduce) {
if(rereduce) {
// still need to do this
} else {
var channels = {};
ops.forEach(function(op) {
var channel = (channels[op.channel] = channels[op.channel] || {channel: op.channel, users: []});
if(op.operation == "join") {
if(channel.users.indexOf(op.property) == -1) channel.users.push(op.property);
}
});
return channels;
}
}
// example operations
{
"_id": "b3af688ce356487f5ca3176400edd87c",
"_rev": "1-78203bea28805a6c97544b71d89ae09b",
"operation": "join",
"property": "mathijs",
"channel": "couchdb"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment