The Firebase Firestore documentation says:
Get multiple documents from a collection
You can also retrieve multiple documents with one request by querying documents in a collection. For example, you can use where() to query for all of the documents that meet a certain condition, then use get() to retrieve the results:
var citiesRef = db.collection('cities');
var query = citiesRef.where('capital', '==', true).get()
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
})
.catch(err => {
console.log('Error getting documents', err);
});
If I have a collection with N documents, would I incur a N-read fee or a single read, for the above query?
Is there any way to retrieve the read/write count on a per call basis using the SDK?
As some background for my rational for asking, I have a single collection with a large number of documents (around 20,000). I want to export the entire collection's documents in the most cost efficient manner (least reads).
If you need a count, just use the collection path and prefix it with counters . As this approach uses a single database and document, it is limited to the Firestore constraint of 1 Update per Second for each counter.
According to Firebase pricing, writes are defined as: 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 as a single write. Meaning that one document created is one write.
Every document yielded by a query counts as a document read. If your query matches and returns N documents, it will cost N document reads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With