ZenPylon
ZenPylon

Reputation: 538

Are Cloud Firestore subcollections included in document size calculation

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!

Upvotes: 23

Views: 4874

Answers (1)

Lashae
Lashae

Reputation: 1382

It is already stated by @frank-van-puffelen however I would like re-state and share the official references for further emphasis.

TL;DR;

Size of the subcollection doesn't affect the parent document's size in any way.

References

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.

Upvotes: 33

Related Questions