1
votes

DATABASE STRUCTURE:

I have a Collection "User" and the user has 1 document named "Parent Document A" and this document has a Sub-Collection named "child" with 2 documents.

Question 1: If I only read the document named "parent Document A" will I will be charged for 1 read or 3 reads (including sub collection's 2 documents).

Question 2: If I read the 2 documents in the Sub-Collection, will I be charged for 2 reads or 3 reads (including the parent document).

Thanks in advance experts.

2

2 Answers

2
votes

If I only read the document named "parent Document A" will I will be charged for 1 read or 3 reads (including sub collection's 2 documents).

Firestore queries are shallow and do not read documents in subcollections. It is just 1 read in this case.

If I read 2 documents in the Sub-Collection will I will be charged for 2 reads or 3 reads (including parent document readed).

Firestore queries do not read or consider documents in parent collections.

Firestore queries only consider documents within the collection being queried. They don't consider any documents outside that collection, whether "parent" or "child" documents. The only exception to this is collection group queries, which consider all document in all collections with the same name.

0
votes

Answer 1 : only one read (sub collections docs will not be read) Answer 2 : only two reads (if you are reading from sub collection then parent document will not be read)