1

I found out that listening to document changes will always download the full document over and over.

I have a problem with this in the following scenario: The size of a document is approaching 1 MiB (which is the limit for document size). Now, there is a number field that is the only field updating, which is just a few bytes. However, listening to this change (e.g. likes on a post) will always download the full 1 MiB of data, even though a few bytes would have been sufficient.

I know that I could just move the data that takes up most of the 1 MiB to a subcollection to a single document, but this would not only be unidiomatic and seem very counterintuitive, but also significantly increase my Firestore bill because I would need two instead of one document reads to retrieve the data initially.

Is there any other way to solve this problem?

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
  • You already seem to know that Firestore always reads the full document. You've also thought of a workaround that seems valid, and will probably save you more in bandwidth usage, and the cost of the extra read. Given that knowledge, I'm not sure what your question exactly is. – Frank van Puffelen Mar 09 '19 at 20:13
  • See Franks Answer here it might help you as you are specifically looking to update a single field **Number** in a document instead of downloading the complete document over and over.[Link](https://stackoverflow.com/a/55082045/10953546) – Fire-In-D-Hole Mar 09 '19 at 22:25
  • @FrankvanPuffelen I noticed this behavior, but I was not sure whether there was no way to prevent it. If it is really the case, that could be a potential answer from you. – creativecreatorormaybenot Mar 09 '19 at 22:54

1 Answers1

1

Firestore always returns complete documents. There is no way to get it to return a subset of the fields in a document, neither by explicitly asking for those fields (akin to a SELECT FIELD1, FIELD2 statement), nor implicitly asking (as you do by wanting only modified fields).

If you want to limit bandwidth usage for frequently changing documents with a large payload, your workaround of putting the more static part of the data in a separate document is valid.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807