couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hank Knight <hknight...@gmail.com>
Subject Re: CouchDB: Group results by unique values
Date Fri, 26 Jul 2013 20:51:20 GMT
I don't care about the string length.  I thought that fruit.length
would count the instances of that fruit however at a closer glance it
only tells me how many characters are in the string!

Specifically, how can I use function _count?

Please look here:

https://zurv3aqzm.iriscouch.com/_utils/database.html?fruit/_all_docs
https://zurv3aqzm.iriscouch.com/_utils/database.html?fruit/_temp_view

Thanks.

On Fri, Jul 26, 2013 at 5:41 PM, Stanley Iriele
<siriele@breaktimestudios.com> wrote:
> Also you can use arrays as keys as well in group by that.. So [fruit,
> weight, etc,] and value can be whatever you want...then use the couchdb
> built in reduce function _count
> On Jul 26, 2013 4:34 PM, "Stanley Iriele" <siriele2x3@gmail.com> wrote:
>
>> Is fruit a string or an array here?.. Why do you care about the fruit
>> length?
>> On Jul 26, 2013 4:29 PM, "Hank Knight" <hknight555@gmail.com> wrote:
>>
>> > I have 1000 of rows but the containing data about fruit.  There are
>> > only 10 unique values for the field "fruit".
>> >
>> > I would like to count the total number of occurrences for each unique
>> > "fruit" value.
>> >
>> > This returns 1000 results:
>> >
>> > function(doc) {
>> >   if (doc.fruit) emit(doc.fruit,doc.fruit.length);
>> > }
>> >
>> > How can I limit the results so each unique value for fruit is only
>> > returned once?
>> > In MySQL I would use something like:
>> > SELECT `fruit`, COUNT(`fruit`) GROUP BY `fruit`
>> >
>> > ---
>> > Thanks!
>> >
>>

Mime
View raw message