Created
December 20, 2012 12:10
-
-
Save jiangzhuo/4344952 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
function Map() { | |
emit( | |
{ClientVersion:this.ClientVersion, PublisherId:this.PublisherId}, // how to group | |
{SessionCount: 1, userIds:[this.UserId]} // associated data point (document) | |
); | |
} | |
function Reduce(key, values) { | |
var reduced = {SessionCount:0,userIds:{}}; // initialize a doc (same format as emitted value) | |
values.forEach(function(val) { | |
reduced.SessionCount += val.SessionCount; // reduce logic | |
val.userIds.forEach(function(uid){ | |
if(!reduced.userIds[uid]){ | |
reduced.userIds[uid]=true; | |
} | |
}); | |
}); | |
return reduced; | |
} | |
function Finalize(key, reduced) { | |
return {UserCount:reduced.userIds.length, SessionCount:reduced.SessionCount}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment