0

I am not sure how I should structure my Firestore database, so it can scale safely. The general structure is a relatively low amount of projects, but each project can have many thousands of subprojects. Is it better to structure the subprojects as a sub-collection of each project or should I structure the project and subproject collection in the root and link the subprojects to the parent project? I try to visualize it. The subcollection object should represent a nested collection

   {
      "projects": {                        //collection
        "project_uid": {                   //document
          "name": "some_name",            
          "some_url": "some_url",
          "createdAt" : 1548418304
        },
        "project_uid1": {                  //document
          "name": "some_name",
          "some_url": "some_url",
          "createdAt" : 1548418304
        }
      },
      "subrojects": {                       //collection
        "subroject_uid": {                  //document
          "thread_uid": "some_id",
          "title": "some_title",
          "content": "some_content"
        },
        "subroject_uid1": {                 //document
          "thread_uid": "thread_uid1",
          "title": "some_title",
          "content": "some_content"
        },
        "subroject_uid2": {                 //document
          "thread_uid": "thread_uid1",
          "title": "some_title",
          "content": "some_content"
        }
      }
    }

Or does it make more sense with parallel collections (If this even works)?

   {
      "projects": {                        //collection
        "project_uid": {                   //document
          "name": "some_name",            
          "some_url": "some_url",
          "createdAt" : 1548418304,
          "subcollection": {                   //collection
            "subproject_uid": {                  //document
              "title": "some_title",
              "content": "some_content"
            },
            "subproject_uid1": {                 //document
              "title": "some_title",
              "content": "some_content"
            }
          }
        },
        "project_uid2": {                  //document
          "name": "some_name",
          "some_url": "some_url",
          "createdAt" : 1548418304,
          "subcollection":{                   //collection
            "comment_uid2": {                 //document
              "title": "some_title",
              "content": "some_content"
            },
          }
        }
      }
vancua
  • 55
  • 2
  • 6
  • As with any NoSQL type database, you should structure your data in a way that suits the queries you expect to make. – Doug Stevenson Jan 25 '19 at 14:28
  • My answer from this post [What is denormalization in Firebase Cloud Firestore?](https://stackoverflow.com/questions/54258303/what-is-denormalization-in-firebase-cloud-firestore) and this post [What is the correct way to structure this kind of data in firestore?](https://stackoverflow.com/questions/53053768/what-is-the-correct-way-to-structure-this-kind-of-data-in-firestore/53057707) will answers your question. – Alex Mamo Jan 25 '19 at 15:22

0 Answers0