Hi,

I'm doing an all docs query without and with a limit. Basically I'm looping 
through all my documents one batch at a time, but I'd like to find out how 
many records there are in total that match the query first before I break 
it up into batches. You know, so I can have a proper progress indicator 
showing how far we've gone.

So I have this code so far:

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];

I know the rowCountQueryRow.value won't get me the count as I've got it 
above, but that's the point of this email.

How do I get the count first when mapOnly = NO? There's no reduce function 
on an all docs query as far as I know.

Thanks,

Brendan

-- 
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/85176c5a-5da3-41c3-81bf-37597abd1029%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to