9
votes

can anybody specify the costs for me in the following scenario:

When a query with a snapshotlistener listens to a collection and one document of the collection will be added or updated, will I be charged for the document that was updated or for all documents in the query?

Example: I have a snapshotlistener on a user collection with a where statement that shows me 20 entries. Now one document in that query will be changed, will I be charged for all 20 documents, because the snapshotlistener returns 20 documents or only for the one that changed?

Thank you!

3

3 Answers

7
votes

Your snapshot listener will fire immediately with the 20 documents that match your query, and subsequently when the document changes.

You will be charged for 21 document reads in this case: the 20 reads for the initial snapshots and then the 1 read for the modified doc.

4
votes

You'll be charged for one read for the changed document.

Frank's answer is correct in that the first time you activate your listener, you'll automatically fetch down all 20 documents, but each subsequent document change will only result in one read.

1
votes

The snapshot listener will fetch all the collection's documents every time you start the activity or the load the fragment. But if something changed in the document while you using the app only one document will get fetched again. So maybe the best way to maintain you budget is using the mvvm pattern with depnding on cach in not important aspects