incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <wout.mert...@gmail.com>
Subject Re: how to count the number of unique values
Date Fri, 15 Oct 2010 12:33:53 GMT
Just wanted to add that if you have a map function that emits (tag, 1) for each tag and then
a reduce function that's just _count, you will have everything you need for painting a tag
cloud.

The view with group=true will list all tags exactly once, with their count. CouchDB doesn't
tell you how many rows are in the result so you'll have to count them yourself.

So you load that entire view in memory and you can draw the tags with their relative sizes.

Wout.

On Oct 12, 2010, at 15:09 , Anand Chitipothu wrote:

> Is it possible to count the number of unique values by writing a couchdb view?
> 
> A typical example is to find the number of tags in a blog application.
> 
> 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?
> 
> Anand


Mime
View raw message