I have the following class method, which returns a CBLQuery scoped to a
given document. It does that by emitting a document-id first, ordering by
that key and setting start- and stop-keys.
Now I have received a handful of crash reports from Crashlytics where this
method crashes when I set the start key to a nil document ID. I cannot
reproduce the crash as the method should only ever be called for a document
that has been stored in the database already. So before I go nuts trying to
figure out when this happens, could it be that Couchbase unsets the
document's `documentID` in certain scenarios? Thanks!
+ (CBLQuery *)resultsByDateForDocument:(CBLDocument *)document
{
NSParameterAssert(document);
CBLView* view = [document.database viewNamed:@"patientResultsByDate"];
if (!view.mapBlock) {
[view setMapBlock:MAPBLOCK({
if ([@"result" isEqualToString:doc[@"type"]]) {
emit(@[doc[@"patient"], doc[@"date"] ?: [[NSDate new] med_isoRepresentation]
], doc[@"_id"]);
}
}) version: @"2"];
}
NSString *docID = document.documentID; // if this is nil...
CBLQuery *query = [view createQuery];
query.descending = YES;
query.startKey = @[docID, @{}]; // ...this crashes
query.endKey = @[docID];
return query;
}
--
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/5605e761-6b8a-4b07-a978-a273fc132797%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.