0

I'm struggling to figure out why I am getting significantly more reads than expected on Firestore. This is the function I executed once from my app:

docs = await getDocs(
                query(
                    collection(db, "openTenders"),
                    where("locationState", "==", queryParams.l.toUpperCase()),
                    orderBy("closeTimestamp"),
                    startAfter(lastTender),
                    limit(20)
                )
            );

I am limiting it to return 20 documents, but am still getting 325 reads. enter image description here

I am wondering if Firebase charges a read per document in an index query? If someone has some insight into this, or if I should go back and and diagnose why my app is behaving this way. Thanks!

OMGItsRob
  • 105
  • 1
  • 2
  • 7
  • Firestore doesn't need to read the document to determine if it matches the condition in the query, as it uses indexes for that. The code you show only gets charged a document read for each document returns (unless there are 0 results, in which case it'll charge 1 document read for the query itself). So the charges are likely coming from somewhere else. For example: do you have the document viewer in the console open? Usage by the Firestore console is also charged, and leads to many more document reads than most devs realize. – Frank van Puffelen May 26 '23 at 18:37
  • Wow that was exactly what it was. Thanks for the info. I'll try not to click that as much :D – OMGItsRob May 26 '23 at 19:03
  • Good to head @OMGitsRob. And thanks Doug for finding the duplicate, which was next on my list. :) – Frank van Puffelen May 26 '23 at 22:37

0 Answers0