My *CBLModel* object has a property string named *url*. I want to get one
single document based on a certain url. This is how I do it now:
CBLView* view = [database viewNamed:@"cachedResponse"];
[view setMapBlock:^(NSDictionary* doc, void (^emit)(id key, id value)){
if ([doc[@"type"] isEqualToString:kCachedType]) {
emit(doc[@"_id"], doc);
}
} version: @"1"];
CBLQuery* query = [view createQuery];
query.postFilter = [NSPredicate predicateWithFormat:@"value.url = %@",
url.absoluteString];
NSError *error = nil;
CBLQueryEnumerator *enumerator = [query run:&error];
if (error) {
NSLog(@"Error running query: %@", error.description);
return nil;
}
if (enumerator.count == 0) {
return nil;
}
CBLQueryRow *row = [enumerator rowAtIndex:0];
MPCachedCBLResponse *response = [MPCachedCBLResponse modelForDocument:
row.document];
>From what I read in documentation the postFilter predicate is ran after the
map block is ran, is this correct ? Do you know some other ideas on how to
get that single CBLModel object that has the url search criteria ?
--
You received this message because you are subscribed to the Google Groups
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/mobile-couchbase/f8810fc0-dd8c-4f01-841a-2097a6d9b2b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.