Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate read/writes on Firestore query/where operation?

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).

like image 602
Andy Fusniak Avatar asked May 02 '18 16:05

Andy Fusniak


People also ask

How do I find out how many documents are in my firestore collection?

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.

What counts as a write in firestore?

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.


1 Answers

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.

like image 182
Doug Stevenson Avatar answered Sep 24 '22 04:09

Doug Stevenson