AoumiS
AoumiS

Reputation: 35

Are only the changes being charged on Firestore onSnapshot?

Example scenario. Chat Channel:

Expected charges: - 1x write - 10x read

The reason I am asking this question is because when I debug the querySnapshot from the onSnapshot callback, I kept seeing 'all' the messages in .docs property (including the new one)

Would like to confirm my expected charges are correct, instead of me being charged for reading the entire collection every time a new message is added.

Upvotes: 0

Views: 93

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138824

Expected charges: - 1x write - 10x read

That's correct. You'll have only 1x write since you add a single message and 10x read since you have 10 users that read that message.

when I debug the querySnapshot from the onSnapshot callback, I kept seeing 'all' the messages in .docs property (including the new one)

That's the expected behavior. If you see all those messages, it doesn't mean that you are charged for all of them, you are charged only for the new one. This is happening because the older messages are coming from the cache.

Would like to confirm my expected charges are correct, instead of me being charged for reading the entire collection every time a new message is added.

Yes, your expectations are correct. You'll be not charged for reading the entire collection every time a new message is added, you'll be charged only with a single read, which is for the last message.

Upvotes: 2

Related Questions