title: Hierarchic structure Firestore and subcollections
body: <p>I am trying to build a database with Cloud Firestore and having read the documentation about <a href="https://cloud.google.com/firestore/docs/data-model" rel="nofollow noreferrer">hierarchic structure</a> I have found another solution to the one present in the documentation example.</p>
  
  <p>I have a <code>collection</code> of categories, and each category can have subcategories. Whereas I could use the system provided in the Firestore documentation example such as <code>collection/document/subcollection/document...</code> I have found <a href="https://docs.mongodb.com/ecosystem/use-cases/category-hierarchy/" rel="nofollow noreferrer">another example</a> for MongoDB where instead of having subcollections it uses nested data in a single document with parent-child relations as described in the image below</p>
  
  <p><a href="https://i.stack.imgur.com/dOk08.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dOk08.png" alt="enter image description here"></a></p>
  
  <p>What approach is better if I want the <code>user</code> to be able to see all the subcategories so the user can categorize a certain <code>event</code>? By better I mean in terms of avoiding multiple connections to the DB (as this is what Firestore prices with).</p>