skip to Main Content

structure of my Firestore database:

Structure of 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.

UI Screenshot

Anyone please suggest to me some ideas to achieve this?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Does the Firestore Group collection gets all docs under multiple documents?

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search