Create MapReduce View for Stat


#1

Hi I would like to know how to create MapReduce view using buitin “_stat” function. I don’t see it any where in the couchbase lite sdks.

This is my view:

[[_database viewNamed: @“viewEventIndex”] setMapBlock: MAPBLOCK({

    if ([doc[@"Type"] isEqualToString:@"Event"])
        emit(doc[@"UserID"], doc[@"EventID"]);
    
}) reduceBlock: REDUCEBLOCK({
    
   @(values.count);

    return   // ** what is the stat function? **

);

}) version: @“1.0”];

Thank you.


#2

Hello @woody_12,

Have you taken a look into…

CBLReduceBlock stats = CBLGetReduceFunc(@“stats”)

and having your setMap: then with…reduce:stats

[[_database viewNamed: @"viewEventIndex"] setMapBlock: MAPBLOCK({
    if ([doc[@"Type"] isEqualToString:@"Event"])
        emit(doc[@"UserID"], doc[@"EventID"]);

     }) reduceBlock:stats ];    

Does that give you the stats logic?


#3

Hi Sweetiewill,

I think the method CBLGetReduceFun() is removed. I see from the class reference that it resides in “CBLReduceFuncs.h” but that header no longer in the latest SDK.

Thanks