I've played with this last night.
There is a groupLevel property, if I set this property to 1 grouping works fine, and each of the result rows contain different emitted key, the value actually is the result of reduce function.
So I can use grouping to get count of cases, if I emit for each case always the same key, like this:
[design defineViewNamed: @"casesByCreateDateCount" mapBlock: MAPBLOCK({
id date = [doc objectForKey: @"createDate"];
NSString* docType = [doc objectForKey: @"type"];
if(date && docType && [docType isEqualToString:@"case"])
emit(@"casesByCreateDateCount", NULL);
}) reduceBlock: REDUCEBLOCK({
return [NSNumber numberWithInt:values.count];
}) version: @"1.0"];
CouchQuery* query = [design queryViewNamed: @"casesByCreateDateCount"];
for (CouchQueryRow* row in query.rows) {
id rowCount = row.value;
NSLog(@"Number of cases: %@", rowCount);
}
I still don't know how good or bad is it in for performance.
I still don't understand, why REDUCE block is ignored if I trying to get count as it described in all NoSQL manuals.