You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Guy Moulton <gu...@gmail.com> on 2009/11/21 22:09:01 UTC
Counting unique items
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
Re: Counting unique items
Posted by Nathan Stott <nr...@gmail.com>.
You can pass reduce=false to turn off the reduce step of views with reduces
if that helps
On Sat, Nov 21, 2009 at 3:09 PM, Guy Moulton <gu...@gmail.com>wrote:
> 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
>
Re: Counting unique items
Posted by Jan Lehnardt <ja...@apache.org>.
On 21 Nov 2009, at 22:09, Guy Moulton wrote:
> 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.
Hi Guy,
this might help you: http://books.couchdb.org/relax/reference/views-for-sql-jockeys#Get%20Unique%20Values%20(SELECT%20DISTINCT%20field%20FROM%20table)
Cheers
Jan
--
Re: Counting unique items
Posted by Guy Moulton <gu...@gmail.com>.
> 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
>
Hi,
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?
Regards,
Guy