On Oct 25, 2016, at 1:58 PM, Todd Freese <to...@filmworkers.com> wrote:Anyone have any thoughts on this? What is the syntax for adding a reduce function to the above map function? This is for a SG view called via the SG REST API.
CBLView *view = [self.document.database viewNamed: @"jobs/uniqueDayNumbersForJob"];
if (!view.mapBlock) {
NSString *const kSceneDocType = [Scene docType];
[view setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString:kSceneDocType]) {
NSString *jobID = doc[@"job_id"];
NSString *sceneID = doc[@"_id"];
NSString *dayNumber = doc[@"dayNumber"];
if (jobID == nil) {
jobID = @"";
}
emit(@[jobID, dayNumber, sceneID], dayNumber); // emit order is fixed because emit element is referred by index from calling method.
}
}) reduceBlock:REDUCEBLOCK({
return @(values.count);
}) version: @"4"]; // bump version any time you change the MAPBLOCK body!
}
CBLQuery *query = [view createQuery];
query.groupLevel = 2;
query.descending = NO;
NSString *myJobId = self.document.documentID;
query.startKey = @[myJobId];
query.endKey = @[myJobId, @{}];
return query;