Created
October 21, 2010 10:05
-
-
Save krawaller/638246 to your computer and use it in GitHub Desktop.
CouchOne Tristania example
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(doc){ | |
if(doc.username && doc.presentation){ | |
emit(doc._id, doc); | |
} | |
} |
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
{ | |
_id: "0DB6DACF-A385-5284-BFD2-519F9AC802BB", | |
_rev: "31-62f831b083c0539e8276f667e357bef2", | |
coords: { | |
latitude: 57.863380432128906, | |
longitude: 11.911527633666992 | |
}, | |
presentation: "moo moo moo moo", | |
username: "David", | |
favalbum: "rubicon", | |
favtracks: { | |
"rubicon": "patriotgames" | |
} | |
} |
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
{ | |
rows:[ | |
{ | |
key:null, | |
value: { | |
favalbum: { | |
votes:2, | |
results: { | |
rubicon: { | |
votes: 2, | |
percentage:100 | |
} | |
} | |
}, | |
favtracks: { | |
rubicon: { | |
votes: 1, | |
results: { | |
patriotgames: { | |
votes:1, | |
percentage: 100 | |
} | |
} | |
} | |
} | |
} | |
} | |
] | |
} |
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(doc){ | |
if(doc.favalbum || doc.favtracks){ | |
emit(doc._id, doc); | |
} | |
} | |
function reduce(keys,values){ | |
var a,t,stats = { favalbum: {votes: 0,results:{}}, favtracks: {} }; | |
values.forEach(function(u){ | |
if (u.favalbum){ | |
if (!stats.favalbum.results[u.favalbum]){ | |
stats.favalbum.results[u.favalbum] = {votes:0}; | |
} | |
stats.favalbum.results[u.favalbum].votes++; | |
stats.favalbum.votes++; | |
} | |
if (u.favtracks){ | |
// omitted for brevity | |
} | |
} | |
return stats; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment