Created
June 19, 2015 14:06
-
-
Save hypesystem/bdc79182093396b5b4a9 to your computer and use it in GitHub Desktop.
CouchDB (Hardcoded) Multi-dimensional Query (by using List)
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: "_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)); | |
} | |
} | |
} |
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
... |
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
// 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