structure of my Firestore database:
Restaurant –> Data –> Menu –>All dishes
I want to get all dishes under all restaurants and show them on a single page just like all under breakfast names of all restaurants having breakfast and under them, all breakfast just like in the image below.
Anyone please suggest to me some ideas to achieve this?
2
Answers
If you want to order the documents (dishes) to the restaurant, I would recommend not using a group query but rather to query the restaurants and than for each restaurant query the dishes in a single query.
Collection Group queries would have some issues in your case, mainly that you could not easily query more documents (dishes) of the same restaurant in one query when the user swipes to the left. They are great if you would want a page where there are all dishes without the restaurant association, but if you want a structure like your UI screenshot suggest, I would go with separate queries.
A collection group query, will always return documents from all collections with the exact same name, no matter if it’s a top-level collection or a sub-collection.
So in your example, you can get all dishes by using a collection group query on the menu sub-collection.