Cloud Firestore data architecture for Nested Data Structures

Viewed 71

What is the ideal Cloud Firestore data architecture for nested bullet lists?

I am starting a side project to build a small “bullet list” app, similar to the core functionality of Workflowy. The basic premise is that you can create nested text bullet lists of arbitrary depth.

  • Any particular bullet item can have many children bullet items
  • You can collapse/expand the children of a particular bullet item
  • You can delete any particular bullet item and all its children
  • It would also be nice if you could drag/drop any bullet item (and its children) to a different position in the list

I would like to use Firebase and React to build this. Considering the basic functionality outlined above, what would be the optimal data architecture in Cloud Firestore? What is the best way to capture the parent/child relationship between bullets? What would provide a good balance of performant reads (display all bullets) and writes (delete all children of a particular bullet)?

Should I simply keep all my “bullet” documents in a root level “bullets” collection and track that bullet’s children via a “children” field that is an array of IDs or references to the children bullets? Ex:

bullets
  bullet_1
    text: "I am the bullet text."
    parent: null
    children: [bullet_2]
  bullet_2
    text: "I am also text."
    parent: bullet_1
    children: [bullet_3, bullet_4, bullet_5]
  bullet_6
    text: "I am also text."
    parent: null
    children: []

Or, rather than keeping an array of children IDs or references, should I instead keep the children bullets in sub collections of their parents? Ex:

bullets
  bullet_1
    text: "I am the bullet text."
    parent: null
    children_subcollection
      bullet_2
        text: "I am also bullet text."
        parent: bullet_1
        children_subcollection_2 (are nested subcollections even possible?)
          bullet_3
            text: "I am but lowly bullet text."
            parent: bullet_2
          bullet_4
            text: "I am just more bullet text."
            parent: bullet_2
            ...

0 Answers
Related