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.
Related
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
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.
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.
If I have 1000 documents and I run a query to find 3 documents that meet a certain condition, will that count as reading 1000 or 3 documents?
Document reads are the fundamental unit of billing in Firestore as they relate to queries. Individual queries are not a primary unit of billing, but each query will be billed.
You will be billed for all the documents matched by a query, as those documents will be read and sent to the client. If your query matches no documents, then there is no billing. If your collection has 1000 documents, but your query returns 3 documents, you are charged 3 reads, not 1000.
The exception is that queries that return no documents are billed for a single document read. This means every query incurs a cost of at least one document read, no matter the results. If your query spans multiple requests (because of paging), you are billed at least one document read per request.
Please consult the documentation for Firestore billing to get more detailed information.
As per your query If you are fetching all documents at once on the client end and running your criteria search it will be counted as a single query.
However, if you use the query method of Firestore it will be also counted as a single query.
Note:
Don't have references yet, I am telling through the personal experience.
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.