2
votes

Say I have a collection called text_messages in firestore that has 500 documents in it, and I know the doc_id of one of those documents.

I want to execute the following code to fetch the data of that document down:

doc = db.collection("text_messages").document("my_doc_id").get()
data = doc.to_dict()

So my question is this: does this count as 1 read or 500 reads? I'm asking from a billing standpoint and want to optimize cost.

1

1 Answers

2
votes

Firebase counts as one read for each query, it doesn't matter if your collection has 500 docs or 5000 doc. A single query counts as one read, even if it had to go through 500 docs searching for it in the cloud firestore.

Also keep in mind that, while listening for a query, you are charged for a read each time a document in the result set is added or updated.

// Reading a specific document,
db.collection("text_messages").document("my_doc_id")
    .get() // One read

// Using where query
db.collection("text_messages").where("sender", "==", "jack sparrow")
    .get() // One read

// Reading a whole collection
db.collection("text_messages")
    .get() // One read

You can read more here