What is the best way to get a filtered list of docs in root collection, along with all its child docs, that are stored in the subcollection? Ok, I can get a list of root collection docs, what next: should I query every doc subcollection items separately? I can do that (looks not optimal), but how my original query function should return a list, how can I get it if all sub-docs have already red (all async queries are complete)? Thanks.
1 Answers
Should I query every doc sub-collection items separately?
Yes. Firestore queries are shallow, which means that you can only read documents from the collection that the query is run against. There is no way to get documents from a top-level collection and other sub-collections in a single query. Queries across different collections are not currently supported. So you have to create a separate query for each sub-collection. If you want to get the result of multiple queries, then you should consider using Tasks#whenAllSuccess(), as explained in my answer from the following post:
However, if you're using a sub-collection that has the exact same name in all documents, then you can perform a collection group query. This will return all documents from sub-collections in your database that have the same name.

- 130,605
- 17
- 163
- 193
-
1Hey Konstantin. Is there everything alright? Can I help you with other information? – Alex Mamo May 18 '23 at 06:11