How FireStore document reads in sub collections calculated - firebase

I have a root collection of products that contains 10 documents.
Each document has a subcollection of 100 documents and no other fields.
Now if I read the documents of the products collection by
db.collection("products").get();
how many reads will be charged, Since I'm getting documents of products collection having 10 documents I will be charged for 10 reads? or each document has a subcollection of 100 documents, so I will be charged for 10*100 =1000 document reads?

In Firebase Firestore you will be charged only for data you receive.
When reading a collection you won't get the subcollections with it.
That means if you have 10 produst with 100 items in theire subcollections. You will be charged only for those 10 products you get because you won't get the subcollections with that request.

Related

what counts as document reads in firestore?

In Firestore, If my query only returns 10 results that match the critera, but I have to read all the 1000 documents, how much would be counted as document reads in firestore billing?
If my query only returns 10 results that match the critera,
This will only cost 10 reads.
but I have to read all the 1000 documents
If you are saying you have 1000 documents in the collection but your query returns only 10 documents, then that's 10 reads only.

If I query a collection from firestore with 1 document with 10 text fields in it then will that count as 10 reads or 1 read?

If I query a collection from firestore with 1 document with 10 text fields in it then will that count as 10 reads or 1 read? And how does the firestore count reads to a database?
It'll cost 1 read. You are charged for reads per document and not the amount of data in the document. Make sure you add a limit while fetching a collection:
citiesRef.orderBy("name").limit(3);
Since the limit here is 3, it'll charge you (at most) 3 reads. If there's no limit set then the query will fetch all documents costing you N reads where N is number of documents in that collection.
Read more at Understanding Cloud Firestore Billing

Get a collection of N documents cost with Firebase

Get 5 documents from users/ or from users/friends/Mike/sister/Jessica/rabbit... is the same amount of reads on the DB?
I mean, since I need to access to more locations will this increment the amount of reads or it depends only from how many documents I get from the collection?
You are charged only for documents that are returned to the client as a result of query, not for all the documents in the collection. If you want to limit your costs, you should also place a limit on the number of documents that the query can receive.

Firestore billing for nested sub-collections

When querying a deeply nested sub-collection, do you get charged for reading the documents at the top of the hierarchy or do you just get charged for the documents that belong to the sub-collection that is being read.
You get charged for the documents that the server needs to read for you. If you only read documents from the subcollection, you will only get charged for those. There is no implicit read-from-top-level-collecton required for reading from a subcollection.

Firestore Pricing - Does The Amount of Documents In a Collection Matters?

I have read in the documentation that I'm being charged for the amount of the requests I'm making to read, write or update documents. I have also read that reading a collection is priced the same as a reading a document ("For queries other than document reads, such as a request for a list of collection IDs, you are billed for one document read."), correct me if I'm wrong.
My question is: Does reading a collection with a big amount of documents in it (let's say - 10,000 documents) is priced the same as reading one with 10?
I'd like to get some explaination about it...
It depends on what you mean by "reading a collection", but for most people this means "querying a bunch of documents from a collection". And the answer is that the pricing generally depends on the number of documents retrieved.
To oversimplify things just a bit:
If you have a collection of 10 employees and you run a collection("employees").get() call, you will get back 10 employee documents, and be charged for 10 reads.
If you have a collection of 10,000 employees and you run a collection("employees").get() call, you will get back 10,000 employees, and be charged for 10,000 reads.
If you have a collection of 10,000 employees and you run a collection("employees").get().limit(10) call, you will get back 10 employees, and be charged for 10 reads.
If you have a collection of 10,000 employees, 4 of which are named "Courtney" and you run a collection("employees").where("first_name", "==", "Courtney") call, you will get back 4 employees and be charged for 4 reads.

Resources