incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stanley Iriele <siri...@breaktimestudios.com>
Subject Re: CouchDB: Group results by unique values
Date Fri, 26 Jul 2013 22:12:25 GMT
>From what I've seen its good practice to put a doc.type to differentiate
docs... Could you copy paste a sample doc here and we can work out the map
reduce function. Coming from rdbms could be a little challenging
On Jul 26, 2013 6:08 PM, "Stanley Iriele" <siriele@breaktimestudios.com>
wrote:

> I'm not sure what you ate trying to accomplish...that link just says not
> found. Try getting Erica installed... That will help you out a lot.
>
> When you make your map/reduce function in the reduce section..instead of a
> function... Just put _count. And couchdb will recognize that as a call to a
> built in function.
>
> Regards,
>
> Stanley
> On Jul 26, 2013 4:51 PM, "Hank Knight" <hknight555@gmail.com> wrote:
>
>> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message