Id like some clarification onhow streams work. I have a users collection, where eveyone has a votes field stores as an int. I would like to make a stream listening to the top 5 users in terms of votes. Here's my questions:
- If on initial load, say the top 5 users have vote values of 6,5,4,3,1. Lets say a new user joins the app and gets two votes, beating the user with 1 vote. Will this be reflected in the stream?
- there are many users, but i am only interested in listening to the top 5. When a user not in the top 5 has their votes changed, will I be charged a read?
Thanks!
CodePudding user response:
tl;dr:
- Yes
- No
Longer explanation:
- If you use a realtime listeners and a user joins the top 5 that wasn't in it before, you will get a new event with the new, current top 5 documents. You'll also get a delta snapshot that flags the changes, where the user that is new in the top 5 is marked as
added
, while the user that left the top 5 is marked asdeleted
. - Firestore charges document reads for documents that are read for you on the server. Documents that are not in the top 5 don't need to be read, so there is no charge for those.