Firebase Firestore snapshot read count

2020-08-01 10:26发布

问题:

I am trying to optimize the number of reads my app makes on Firesbase and reviewing the way I use snapshot to monitor real time changes. Imagine I have a snapshot returning the 10 latest documents like the following:

db.collection("cities")
.where("state", "==", "CA").
.orderBy('dateadded', 'desc').limit(10)
.onSnapshot(function(snapshot) {
    ...
})

The doc says

The snapshot handler will receive a new query snapshot every time the query results change (that is, when a document is added, removed, or modified).

Does that mean that every time the query changes I will be billed 10 reads? In this example if a new city is added (so with the latest 'dateadded', so coming first in the query) will it be 1 (just the new city) or 10 reads (the full query).

As a side question where I can see the exact number of read I am at (live so I can test a function and see the corresponding number of reads). The IAM and Admin/Quota seems to provide that under "reads request per day" but it is not live...

I am referring to the Firestore snapshot as described at https://firebase.google.com/docs/firestore/query-data/listen

回答1:

If 1 document changes in query results, you will be billed 1 read. You are not billed for documents that are unchanged. The query snapshot object merely reuses the document data that was in memory from the prior set of results.