If a document in Cloud Firestore has a subcollection, are the documents in those subcollection included in the parent document's size? For example, if I have data like:
rootCollection/
parentDocument:
field1: "value1"
field2: "value2"
...
subCollection/
childDocument:
anotherField: "OfGreen"
...
is the size of childDocument
included in the size of parentDocument
From the storage size calculation documentation, it doesn't sound like the contents of subcollections are included in the parent document sizes, but I just wanted to clarify.
Thanks!
When you listen to the results of a query, you are charged for a read each time a document in the result set is added or updated. You are also charged for a read when a document is removed from the result set because the document has changed. (In contrast, when a document is deleted, you are not charged for a read.)
I saw on the Firebase Firestore documentation that the limits for the "Maximum depth of subcollections" is 100.
It is already stated by @frank-van-puffelen however I would like re-state and share the official references for further emphasis.
Size of the subcollection doesn't affect the parent document's size in any way.
Firestore's Choose a Data Structure document is a very clear and prompt reference for comparing the design alternatives. On this page under the section Subcollections, it is stated that:
Advantages: As your lists grow, the size of the parent document doesn't change. You also get full query capabilities on subcollections.
Moreover, on the Working with Arrays, Lists, and Sets documentation under the Limitations section, it is emphasized that:
Document size - Cloud Firestore is optimized for small documents and enforces a 1MB size limit on documents. If your array can expand arbitrarily, it is better to use a subcollection, which has better scaling performance.
And lastly, although it is not directly related with the question, I would like to use the chance to mention it here, because it yield me to the correct documentation pages when I got the same question as the OP: ecgan/firestore-considerations is a short and remarkable list on Github which tries to summarize the caveats and before-hand considerations for Firestore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With