Ah, so the parameter of reduce( keys, values, re-reduce ) is based on each 
of grouped result, I see. Thank you for answering the beginner level 
question.

I tried to log the activity of reduce block and I found it runs only once 
for each document, no matter what the groupLevel is given. That's a bit 
different from my assumption, say I got 3 records (color, type) and 2 of 
them have the exact same key and the 3rd is totally different. My 
assumption is when groupLevel is 1, couch separates them into two groups 
and call the reduce function twice. But the logger says reduce is called 3 
times although the final result is correct. I'm curious what's behind the 
scene makes the magic job ?


On Thursday, 17 April 2014 06:35:45 UTC+10, Jens Alfke wrote:
>
>
> On Apr 16, 2014, at 9:31 AM, Johnny Caveman <[email protected]<javascript:>> 
> wrote:
>
> Let's say if after map process, the document's key is an date-type-color 
> array, and value is some concrete value need to be aggregated, how to write 
> a REDUCEBLOCK equivalent to *_count*, which allows you to drill down when 
> aggregating associated with groupLevel. Just like 
> this<http://blog.couchbase.com/understanding-grouplevel-view-queries-compound-keys>
> .
>
>
> Just write a trivial reduce block that counts rows. Setting the groupLevel 
> will aggregate the keys together, and the reduce block will give you a 
> count.
> So if you set the groupLevel to 1, you’ll get a row for each date whose 
> value is the number of items with that date.
>
> —Jens
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/07f22029-3d32-4a8a-ade7-fe909171c432%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to