I am using couchbase lite 1.3.0 for an ios app. I am saving the model objects as docs in the db. However I am changing the 'doctype' dynamically while saving. Upon querying with 'docType' id , the cbl view emits wrong/unmatching 'docType'. Couldn't figure out how to fix this.
[view setMapBlock: MAPBLOCK({
if ([doc[@"docType"] isEqual: @"docType1"])
{
emit(doc, nil);
}
})
version: @"1"];
CBLQuery* query = [view createQuery];
query.descending = NO;
CBLQueryEnumerator* result = [query run: &error];
for (CBLQueryRow* row in result) {
//The rows emitted doc of 'doctype2'
}
答案 0 :(得分:0)
更改docType
是好的,我想,问题是您将map
函数针对不鼓励使用的查询参数进行了硬编码,并且还emit
也有完整的文档。 / p>
我可以做到这一点:
[view setMapBlock: MAPBLOCK({
emit(doc[@"docType"], nil);
})
version: @"1"];
然后使用docType1
作为参数进行查询,如果您需要doc
,只需将preFetch to
设置为true。
我知道这会在您想要的内容中引入“冗余”,但我认为它可以解决问题