I have a CouchDB with following doc:
{
"name":"Chris",
"tags":["mustache", "music", "couchdb"]
}
{
"name":"Noah",
"tags":["hypertext", "philosophy", "couchdb"]
}
{
"name":"Jan",
"tags":["drums", "bike", "couchdb"]
}
Map Function:
function(dude) {
if(dude.name && dude.tags) {
dude.tags.forEach(function(tag) {
emit(tag, 1);
});
}
}
Reduce Function:
function(keys, values) {
return sum(values);
}
Now, if I query the view with the ?group=true parameter, I get back the count for each tag:
{"rows":[
{"key":"bike","value":1},
{"key":"couchdb","value":3},
{"key":"drums","value":1},
{"key":"hypertext","value":1},
{"key":"music","value":1},
{"key":"mustache","value":1},
{"key":"philosophy","value":1}
]}
What query should I use to get the value of just "couchdb" alone?
This example was taken from the CouchDB book, while my live application has 1000s of keys and most of the time I just needs to find the count of one individual key.
I am not able to use key= parameter, which is really what I want, as it returns an empty result.
If I query ?group=true&startkey="couchdb"&endkey="drums" I get the count of couchdb alone, but I cannot use startkey= and endkey= because I do not know what the next key will be in a live DB.
What solutions would you recommend in this situation?