cachapa / firedart

A dart-native implementation of the Firebase Auth and Firestore SDKs
https://pub.dev/packages/firedart
Apache License 2.0
174 stars 62 forks source link

collection.get() truncated to 300 items #96

Closed devoteappdevelopment closed 1 year ago

devoteappdevelopment commented 1 year ago

Hi, I am trying to get all of the documents in a collection with:

var theseConstituenciesData = await countriesCollectionReference .document(countryDocId!) .collection('constituencies') .get();

however, the result is always truncated to 300 items. I think it might be related to this issue arising in ListDocuments : https://github.com/googleapis/nodejs-firestore/issues/1342 .

I thought of experimenting with just calling the same function multiple times, but there is no command analagous to "startAfterDocument" that appears in the original firestore/firebase packages so I'm not sure how to grab a different set of 300 items in each call.

I tried setting pageSize very high:

var theseConstituenciesData = await countriesCollectionReference .document(countryDocId!) .collection('constituencies') .get(pageSize: 1000000);

but I still get back 300 documents. How can I get all of the documents when there may 1000's or 10,000's of documents?

Thank you

cachapa commented 1 year ago

This sounds like a hard limitation in the Firebase API, I don't think you can get around it.

If you want to retrieve all of your documents you'll have to iterate through all the pages. Beware that it might have a strong effect on your quota and/or billing.

devoteappdevelopment commented 1 year ago

Thank you for the reply.

For anyone else with the same problem: turns out the query approach doesn't have such a limit.

var theseConstituenciesData = await countriesCollectionReference .document(countryDocId!).collection('constituencies').where('title', isGreaterThan: 'A') .get()

grabs all of the documents.

cachapa commented 1 year ago

Weird, but good to know, thanks