Search code examples
firebasefluttergoogle-cloud-firestorefirebase-console

how to structure multiple levels in firestore


so I'm looking to create the following structure in firestore

code_table: [
   "GIM": [
       {
          "label":"assement",
           "codes": ["A001A","A002A",...]
       },
       {
          "label":"consults",
           "codes": ["A001A","A002A",...]
       }
    ....
] 

Between the documents and the collections I can't seem to be able to get this into the firebase firestore using the web ui (Just creating the test data) in such a way that I can actually query it using the flutter sdk

Any suggestions?


Solution

  • Step by step, here's how I create a top-level collection, a code_table document, a GIM subcollection under that document, and then a document in there.

    1. Create a top-level collection with a code_table document in there. enter image description here

    2. Select the code_table document, and click Add collection enter image description here

      This creates a subcollection under the code_table document in the top-level collection.

    3. Name the collection GIM and click Next enter image description here

    4. Click the Auto-ID link to generate a document ID, and enter the fields for your first document in the nested collection. enter image description here

      Click Save

    5. Now you have a top-level collection, a code_table document in there, a GIM subcollection under that document, and a first document in there. enter image description here