Hierarchic structure Firestore and subcollections

喜你入骨 提交于 2020-01-05 04:18:22

问题


I am trying to build a database with Cloud Firestore and having read the documentation about hierarchic structure I have found another solution to the one present in the documentation example.

I have a collection of categories, and each category can have subcategories. Whereas I could use the system provided in the Firestore documentation example such as collection/document/subcollection/document... I have found another example 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

What approach is better if I want the user to be able to see all the subcategories so the user can categorize a certain event? By better I mean in terms of avoiding multiple connections to the DB (as this is what Firestore prices with).


回答1:


This document discusses nested data and its tradeoffs, "Choose a Data Structure". I'm not sure that the statement about multiple connections for pricing is correct. Firestore charges for number of operations, storage, and network bandwidth.

If all users share a single categories list, you would be able to retrieve the entire list with one operation with your current structure. Note that there is a 1 MiB limit for document size.



来源:https://stackoverflow.com/questions/47509846/hierarchic-structure-firestore-and-subcollections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!