Hey folks,
(New to the list, and to Couchbase Lite, about which I am very enthusiastic!)
I am having trouble getting desired results from an "all docs" query when using
some of the features described in the 1.0.3 "Query Enhancements" documentation
[1]. Specifically, prefixMatchLevel does not seem to work as described.
I wish to retrieve all documents with conflicts whose document ID begins with a
particular prefix (specifically of the form "business.NNN." where NNN is a
number). I instantiate and configure the query like so:
CBLQuery *query = [database createAllDocumentsQuery];
query.allDocsMode = kCBLOnlyConflicts;
The documentation suggests that I should be able to get the relevant rows by
doing this:
query.startKey = query.endKey = [NSString stringWithFormat:@"business.%@.",
business.server_psk];
query.inclusiveStart = query.inclusiveEnd = YES;
query.prefixMatchLevel = 1;
However, this returns no results. (It is not clear whether inclusiveStart and
inclusiveEnd should or should not be YES in this case, but it seems to make no
difference.) I only get a result if I specify a startKey and endKey that
exactly match an existing document ID.
Does prefixMatchLevel not work for "all docs" queries? I did not see such a
caveat mentioned anywhere.
Instead, I have found it necessary to use this approach (stuffing a letter "Z"
onto the end of the number so as to stop up the alphabetic sort):
query.startKey = [NSString stringWithFormat:@"business.%@.",
business.server_psk];
query.endKey = [NSString stringWithFormat:@"business.%@Z.",
business.server_psk];
query.inclusiveStart = YES;
query.inclusiveEnd = NO;
Needless to say, the "Z" technique is kludgy at best. Surely I am overlooking
something. Is there a better approach to achieve my query?
I'm using CBL 1.0.4 from CocoaPods/github.
thanks,
b
[1] https://github.com/couchbase/couchbase-lite-ios/wiki/Query-Enhancements
--
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/A5829239-82F8-480B-BC9C-D49BCE4D28DD%40kashoo.com.
For more options, visit https://groups.google.com/d/optout.