couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Moulton <>
Subject Re: Counting unique items
Date Tue, 01 Dec 2009 12:34:46 GMT
> Hello,
> I'm trying to get a count of the number of unique items in a database.
>  Documents look like this:
> Item: Item_A, User: Dave
> Item: Item_A, User: John
> Item: Item_A, User: Jane
> Item: Item_B, User: John
> Item: Item_B, User: Anne
> In the above example, I'd like to know that there are 2 items.  So
> far, I have a map/reduce that produces one view row for each kind of
> item (similar to the example on the wiki) :
> key: "Item_A", value:"Null"
> key: "Item_B", value:"Null"
> So the number I need is the number of rows in the view.
> According to the wiki, if I pass limit=0, it should give me the
> meta-data, but this doesn't seem to work on views that have a reduce
> function.  I don't want to count rows in the client as there could
> potentially be a very large number.
> Any ideas would be very much appreciated.
> Regards,
> Guy


Thanks very much for the replies.  I can get the total item lines (not
unique), and the count for each unique item.  But I can't seem to get
a count for the number of unique items (a single number).  I have a
work around though - I'm counting them once a day and storing the
result, which is fine for what I need.

I'm interested that using limit=0 to get the number of rows/meta data
for a view doesn't work if there's a reduce function - is this a
limitation of the way the reduce works?


View raw message