Skip to content

Instantly share code, notes, and snippets.

@hypesystem
Created June 19, 2015 14:06
Show Gist options
  • Save hypesystem/bdc79182093396b5b4a9 to your computer and use it in GitHub Desktop.
Save hypesystem/bdc79182093396b5b4a9 to your computer and use it in GitHub Desktop.
CouchDB (Hardcoded) Multi-dimensional Query (by using List)
{
_id: "_design/user_actions",
_rev: "some-revision",
views: {
what_ever: {
map: function(doc) {
// ...
}
}
},
lists: {
that_list: function() {
start({
headers: {
"Content-Type": "application/json"
}
});
var result = {};
var row;
while(row = getRow()) {
var userId = row.value.userId;
var action = row.value.action;
if(!result[userId]) {
result[userId] = {};
}
if(!result[userId][action]) {
result[userId][action] = 0;
}
result[userId][action]++;
}
send(JSON.stringify(result));
}
}
}
// when calling http://couchurl/db/_design/user_actions/_list/that_list/what_ever?startkey=x&endkey=y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment