I'm having trouble doing a query on a combination of a string ("doctype") and an int ("id").
I have the following mapfunction:
[self.viewByDocTypeAndId setMapBlock: MAPBLOCK({
if (doc[@"doctype"] != nil && doc[@"id"] != nil) {
emit(@[doc[@"doctype"], doc[@"id"]], doc);
}
}) version: @"1.5"];
Given this data (there a several documents that have these properties):
NSString *doctype = @"tablemap";
int id = 193;
This logs nothing:
CBLQuery* query = [databaseManager.viewByDocTypeAndId createQuery];
query.keys = @[doctype, @(id)];
for (CBLQueryRow * queryRow in [query run: &error]) {
NSLog(@"%@", queryRow.value);
}
And this does:
query = [databaseManager.viewByDocTypeAndId createQuery];
for (CBLQueryRow * queryRow in [query run: &error]) {
if ([queryRow.value[@"doctype"] isEqualToString: doctype] && [queryRow.value[@"id"] intValue] == id)
NSLog(@"%@", queryRow.value);
}
Why does the first query return zero matches ? Is my map function wrong ? The .keys ? Or both ?