[self.view setMapBlock: MAPBLOCK({
if ([doc[@"doctype"] isEqualToStringCaseInsensitive: @"orderline"]) {
NSInteger orderId = [doc[@"orderId"] intValue];
if (orderId != -1) {
emit(@[@(orderId)], @1);
}
}
if ([doc[@"doctype"] isEqualToStringCaseInsensitive: @"order"]) {
NSInteger orderId = [doc[@"id"] intValue];
NSString *firstName = [doc[@"firstName"] length] ? doc[@"firstName"] : @"";
NSString *lastName = [doc[@"surName"] length] ? doc[@"surName"] : @"";
NSString *email = [doc[@"email"] length] ? doc[@"email"] : @"";
NSString *phone = [doc[@"phone"] length] ? doc[@"phone"] : @"";
NSNumber *vip = [doc[@"vip"] intValue] ? @1 : @0;
NSString *avatarUrl = [doc[@"avatarUrl"] length] ? doc[@"avatarUrl"] : @"";
emit(@[@(orderId), firstName, lastName, email, phone, vip, avatarUrl], @0);
}
}) reduceBlock: ^id(NSArray *keys, NSArray *values, BOOL rereduce) {
return [CBLView totalValues: values];
} version: @"0.44"];
I dont see how this could work; grouplevel 1 wont give me the extra properties I need and grouplevel 7 wont give me proper aggregation.
(what I need is several properties of doc type X and the count of doc type Y that is related to an instance of type X, in a single query)