Getting your data count in CouchDB can be easy with something like Couchdbkit, but in the event you want to take it directly on Futon (which is a sweet and simple interface), you can write your own M/R by creating a design document.
Let's say I have a bunch of documents about people who code Python. So the average man has a doc like the following:
{
"_id": "34234r3fewef4q3edcf32eqwdd23",
"_rev": "2-sdsfrf34efr3wef23de2wed32",
"name": "Kenny Shen",
"python": "Yes",
"django": "Yes",
"sql": "No",
"type": "Human"
}
And I want to basically get the guys who are a 'Yes' in Django and do a count. So I'll create a design document in the CouchDB database:
{
"_id":"_design/get_people_who",
"views": {
"do_django_gigs": {
"map":"function(doc) {
if(doc.type == 'Human') {
if(doc.django == 'Yes') {
emit(doc.name, 1);
}
}
}"
}
}
Notice that the map function uses emit() to return the (keys,values) from the query, and instead of the usual doc._somelement return for values I just asked for a '1' instead. This allows me to do something similar to a SQL aggregate using a reduce function, which follows next:
"reduce":"function(keys, values) {
return sum(values);
}"
Remember that unlike map functions which use emit() to return the results, we use return for reduce functions and keeping the goal of trimming down the list returned by map functions.
So whenever I want to get a quick count in the above example I could just type in my browser:
http://localhost:5984/mycouchdata/_design/get_people_who/views/do_django_gigs
and get a JSON return like:
{"rows":[
{"key":null,"value":12}
]}
viz. 12 people...etc.