Im using firestore as the database of my flutter app which manage patients information , in my view all patients screen im getting all documents from the 'patients' collection
StreamBuilder<List<Patient>>(
stream: FirebaseApi().getAllPatients,
initialData: [],
builder: (context, snapshot) {
var data = snapshot.data;
my question is firebase charge all the reads at the following line ?
stream: FirebaseApi().getAllPatients,
or if i filtered the data coming from the stream inside my StreamBuilder Builder Property it will charge data used after filtering ?
for example if i filtered and used only the documents where data.country == 'USA' from that stream (in total 100 documents) will it be count as 100 reads or total documents count ?
if so is there anyway to filter the data like this before getting it from firestore ?
CodePudding user response:
If the are N documents in a collection you fetch all the documents then you are charged for N reads. However, if you use queries e.g. where("data.country", "==", "USA")
then you would be charged for number of documents that match this condition and are returned. So if there are 100 docs with USA then you'll be charged 100 reads only even if there are millions of total documents in the collection.
You can also paginate the data to save reads by loading only the data required.