This is a very basic question but I'm not sure if I understand this correctly, and I didn't find sources that completely clarified it for me.
Firestore documents are always saved in collections. And a collection can have as many documents as you want, but every document has a max size of 1MB.
I've seen that subcollections must be created this way:
DocumentReference messageRef = db
.collection("rooms").document("roomA")
.collection("messages").document("message1");
So we have a collections messages
UNDER a document roomA
. So therefore the max size for the whole (sub) collection messages
should also be 1 MB since it is a child from a document, so everything stored in messages
is also stored in roomA
.
Therefore you couldn't save that many douments in messages
.
Or do I understand this wrong?
I've also read that Firestore is shallow. Would this mean in this case, that a document stored in messages
is NOT also stored in the parent document roomA
?
In that case you could have as many sub-collections of roomA
as you want, as long as their names added up are less than 1 MB in total?
And each of these sub-collections itself can have as many documents as you want.
Which is right?