Reduce functions _count, _sum, _stats not working
Hey there, I'm trying to count something with:
function (doc, meta) { emit(meta.id, 1); }
and the reduce function is just _count. _sum and _stats don't work either.
There are 3 items in the bucket but the result is:
Key: null
ID: undefined
Value: 3
Why?
Edit: My CB version is 2.0.0 community
It's supposed to count the appearances of meta.id. Basically means the result should be something like this:
Key: firstkey Value: 1 Key: secondkey Value: 1 Key: thirdkey Value: 1
Hello,
Are you passing a group level when querying your view?
When you use the a reduce function this is applied to a group of keys.
By default when you call the view you do not have any group selected so the reduce is done at the root level, so if you have 3 documents the count will be 3.
When querying your view you should pass a group level, for example:
&group_level=1
Let me know if this fix your issue.
Regards
Thank you very much dude, that works for me. Didn't think of that group thing.
The result had "value: 3" and you had 3 items in the bucket...
Seems like _count is working just fine, or? ;)