Quick question about how firestore reads are calculated. Say I have a collection with 100 items in it, and I do
citiesRef.order(by: "name").limit(to: 3)
This would technically have to look at all 100 items, order them by name, and then return 3. Would this count for 3 reads or would it count for 100 reads, since we're looking at 100 items?
Thanks.
If the above query returns 3 documents then it would count as 3 reads.
You are charged for each document read, write, and delete that you perform with Cloud Firestore.
Charges for writes and deletes are straightforward. For writes, each set or update operation counts a single write.
Charges for reads have some nuances that you should keep in mind. The following sections explain these nuances in detail
https://firebase.google.com/docs/firestore/pricing#operations
Related
If I get a document by .collection('users').where('uid', isEqualTo, widget.uid) or by .collection('users').doc(widget.uid) will I read the database the same number of times?
You are charged one read for every document that matches your query when it is executed. It does not matter how you make that query - what matters is the number of documents returned to the app.
If your where query returns exactly one document, then it is not any different in price or performance than one using doc.
The former returns a QueryFieldFilterConstraint while the latter returns a DocumentReference. The DocumentReference is preferable because it can be used to write, read, or listen to the location.
Naturally, a query must read every id in the referenced collection (this is probably indexed) while a reference points to a single id. In terms of pricing, aggregateQueries documentation is actually returning a page not found error at the moment?
See Understand Cloud Firestore billing
For aggregation queries such as count(), you are charged one document
read for each batch of up to 1000 index entries matched by the query.
For aggregation queries that match 0 index entries, there is a minimum
charge of one document read.
For example, count() operations that match between 0 and 1000 index
entries are billed for one document read. For a count() operation that
matches 1500 index entries, you are billed 2 document reads.
In the docs it says "$0.10/million reads".
I have a collection with a 1 million documents. I was testing some intensive queries just for one day by myself and my account accumulated a charge of $26.
Not sure how I got there.
So I need to know the precise definition of a "read". Is it each time a document is accessed from disk?
At the time of writing https://www.mongodb.com/pricing reads:
Item
Description
Pricing
Read Processing Unit (RPU)
Number of read operations* to the database * Sum of documents read divided by 4KB and index bytes read divided by 256 bytes
$0.10 / million for the first 50 million per day*
If I get it, 1 read is fetching up to 4Kb of a document or up to 256b of index, e.g. querying whole million of documents in the first stage of an aggregation pipeline costs $0.1 if your documents are about 4Kb each.
I would strongly advise to talk to Atlas support tho. Don't rely on my understanding of what's written there.
my daily quotas has just been resetted so I figured out it was the moment to go on my Firestore user interface to know how much reads where counted simply by retrieving documents.
I have 11 documents each of them have 3 sub-collections (inside of them a certain number of documents) plus 1 dummy document with no sub collection and connecting to the firestore UI counts me 36 reads (1 document is opened - its sub collection are closed);
I though it was 1 read/document retrieved without taking in account sub collections?
36 reads how is this even possible? Would this mean my 12 documents are read 3 times each?
here is my data structure:
myCollection: {
$docId: {
data:myDate
subCollection1:{
$subDocId
}
subCollection2:{
$subDocId
}
subCollection3:{
$subDocId
}
}
}
I have tested it on a completely fresh project. Indeed using the front end UI in the console it used around 2 times more than the number of documents. I created 6 documents with one field in one collection and every listing gave me usage of 12 reads. If you add some sub-collection it might be more.
But first of all I think that console UI is not meant to be used as a working interface, but rather for support/design purposes which means entered occasionally. With this assumption matter of cost effectiveness is less important. If you have 50 000 reads free each day and 0.036$ per 100 000 reads, a few hundred reads more when using the UI just not make any difference in costs.
The larger number of reads might be the result of implementation. Firestore is billed based on API calls, probably some items are queried even if they are not seen at the beginning to improve user experience or due to some other feature of the UI.
Firestore cost documentation here.
is there a way to view the reads/writes in mongodb on a per collection-basis? I would like to see how many documents have been read and written on a specific collection.
We are currently researching the costs of some specific queries and try to find out more about if they are heavy read- and/or write-tasks.
Thank you :-)
Yes you can. You can perform db.collection.stats()
this will return the size and count of documents, index information and a lot of other useful information. But you want to count the number of reads and writes performed on a specific collection. For that you can use mongostat. It captures and returns the counts of database operations by type (e.g. insert, query, update, delete, etc.). These counts report on the load distribution on the server. Read more about mongostat on their documentation. Here's the link https://docs.mongodb.com/manual/reference/program/mongostat/#bin.mongostat
I'm trying to understand Firestore's billing but don't understand exactly what a read/write/delete request is.
If I delete 100,000 items in a single request does that count as 1 delete request or 100,000 delete request?
Also, if a single query returns 250 rows (documents?) does that count as a single read or 250 read requests?
Read and write operations are billed per document affected. So, your examples would incur the cost of 100,000 deletes and 250 reads.