On 2010-10-12 15:09, Anand Chitipothu wrote:
Is it possible to count the number of unique values by writing a couchdb view?

Consider the following 2 docs.

{
     "_id": "posts/1",
     "title": "post 1",
     "tags": ["foo", "bar"]
}

{
     "_id": "posts/2",
     "title": "post 2",
     "tags": ["foo", "foobar"]
}

Is it possible to find that there are 3 tags?
Yes. Just write a map function that emits all tags it finds (not checked and probably wrong):

function(doc) {
    for(tag in doc.tags) {
        emit(tag, null);
    }
}

In the reduce-function, just use _count (http://wiki.apache.org/couchdb/Built-In_Reduce_Functions).

Regards,

Michael.

Reply via email to