0

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'

}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Changing docType is OK I think, the problem is you map function is hard coded against a query parameter which is not encouraged and also you emit a full doc as well.

I can achieve what you are trying to do with this:

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

and then query using the docType1 as a parameter, if you need the doc just set the preFetch totrue`

I'm aware that this will introduce 'redundancy' to what you want, but I think it solves the problem

Chinh Nguyen
  • 583
  • 1
  • 7
  • 14