incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: CouchDB: Counting Total Occurrences of Unique Items
Date Sun, 28 Jul 2013 18:40:33 GMT
add ?group=true

On 28 July 2013 19:36, Hank Knight <hknight555@gmail.com> wrote:
> Aurélien,
>
> I do not like the resulting format.
>
> Using your code, I get this:
> "fruit" : 19
>
> I want this:
> {gooseberry: 3, cranberry: 1, plumb: 1, grapefruit: 2, lime: 1,
> strawberry: 4, orange: 1, blueberry: 1, watermelon: 2, peach: 2,
> lemon: 1}
>
> So how can I get a count of all types of fruit, broken down by the
> type of fruit?
>
>
> I need to know specifically how many occurrences there are are
> "strawberry" as well each of the other types of fruit.
>
> https://zurv3aqzm.iriscouch.com/_utils/database.html?fruit/_design/zzz3/_view/zzz3
>
>
>
> On Sun, Jul 28, 2013 at 2:48 PM, Aurélien Bénel <aurelien.benel@utt.fr> wrote:
>> Hi Hank,
>>
>>> For performance reasons, should anything be moved from the reduce function to
the map function or to an additional reduce function?
>>
>>
>> Indeed.
>>
>> Here is my tip: always try to change your map so that you can use a builtin reduce
function.
>>
>> MAP
>> ===
>>
>> function (o) {
>>   if (o.fruit) {
>>     emit(o.fruit, null)
>>   }
>> }
>>
>> REDUCE
>> ======
>>
>> _count
>>
>>
>> In the case you wouldn't like the resulting format, use a list on it.
>>
>>
>> Regards,
>>
>> Aurélien

Mime
View raw message