Hello i want to create firebase database for groceries store. I have categories and under each category i have subcategories and some of these subcategories has sub-subcategories and under those there are products. how can i structure that in firebase database? firebase structure
there i would suggest this way, may be it'll helpful.
as you can see above image, i have a category tree, following which consists of two child nodes which Category and ParentId. In your case i will suggest get all categories where parentId equal to Zero.
firebase.database().ref("Category").orderByChild("ParentId").equalTo(0);
which will return all Categories. then when you click a category query like below
firebase.database().ref("Category").orderByChild("ParentId").equalTo("Pass your Category Id here");
which will return all sub-categories based on the Category that you choosed.
In your case, you can add another child node like SubCategoryParentId for your subcategories which has subcategories and query like below
firebase.database().ref("Category").orderByChild("SubCategoryParentId").equalTo("Pass your Subcategory Id here");
which will return all subcategories for the subcategories you choosed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With