CouchbaseLite 1.3.0 view querying id of doctype

时间:2017-12-17 08:21:28

标签: couchbase-lite couchbase-view

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'

}

1 个答案:

答案 0 :(得分:0)

更改docType是好的,我想,问题是您将map函数针对不鼓励使用的查询参数进行了硬编码,并且还emit也有完整的文档。 / p>

我可以做到这一点:

[view setMapBlock: MAPBLOCK({
    emit(doc[@"docType"], nil);
})
version: @"1"];

然后使用docType1作为参数进行查询,如果您需要doc,只需将preFetch to设置为true。

我知道这会在您想要的内容中引入“冗余”,但我认为它可以解决问题