NSError *queryError = nil;
CBLQuery *docsQuery = [self.databaseDocument.backgroundDatabase createAllDocumentsQuery];
docsQuery.allDocsMode = kCBLBySequence;
docsQuery.startKey = @(sequence.integerValue + 1);
// Get the count of records
docsQuery.mapOnly = NO;
CBLQueryRow *rowCountQueryRow = [[docsQuery run: &queryError] nextRow];
NSNumber *fullRecordCount = rowCountQueryRow.value;
NSLog(@"Full record count: %@", fullRecordCount);
// Now fetch all the documents
docsQuery.mapOnly = YES;
if (limit) {
docsQuery.limit = limit;
}
CBLQueryEnumerator *docsEnumerator = [docsQuery run: &queryError];