'Get parent collection & sub collection document on firebase
Solution 1:[1]
There is no way to read from both the parent collection and the subcollection in one operation. Read always come from one (type of) collection, which is sometimes explained as "all reads in Firestore are shallow".
You can either:
- Read the parent collection, and then for each (relevant) document read its subcollection as a separate operation.
- Read the parent collection, and read all
SubCategorycollections in one go with a collection group query.
The second approach performs fewer calls to the server, but has a higher chance of reading more documents than needed, if (for example) you may not want the SubCategory collection from some documents.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |

