+ (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;
}
Yes, this is what seems to be happening, I can't see it from the stack trace but I think this is actually coming from a CBLModel that has been deleted, and while the model instance is still around the document is gone.