firebasefirebase-realtime-databasehierarchical-datamaterialized-path-patternnosql

How to store hierarchical data within Firebase


In SQL, I have used nested sets to store hierarchical data. I am trying to do the same with Firebase. In theory, the hierarchy could be "n" levels deep, but in actuality will probably be only 5-7 levels deep.

I have done quite a bit of research. This Mongo DB documentation suggests only using nested sets on static trees. My data will change quite a bit over time. The same document leads to the conclusion that materialized path is the way to go.

Does anyone have experience with this?


Solution

  • Storing data is never the problem, querying the data efficiently is. Given that the Firebase Database stores data in a JSON tree, it can naturally store hierarchies very efficiently. But the Firebase documentation recommends against such nested data structures, since they are harder to secure and to query efficiently.

    But it all depends on what data you want to store and how your app wants to access it. For a good introduction, I recommend this article on NoSQL data modeling.