层次结构Firestore和子集合 [英] Hierarchic structure Firestore and subcollections
问题描述
我正在尝试使用Cloud Firestore构建数据库,并已阅读有关层次结构的文档结构我发现了文档示例中存在的另一种解决方案.
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.
我有一个类别的collection
,每个类别可以有子类别.尽管我可以使用Firestore文档示例中提供的系统,例如collection/document/subcollection/document...
,但我发现
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
如果我希望user
能够看到所有子类别,以便用户可以对某个event
进行分类,哪种方法更好?更好的是,我要避免与数据库的多个连接(因为这就是Firestore的价格).
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).
推荐答案
该文档讨论了嵌套数据及其权衡,.我不确定有关用于定价的多个连接的声明是否正确. Firestore收取的操作次数,存储空间和网络带宽费用.
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.
如果所有用户共享一个类别列表,则可以使用当前结构通过一次操作检索整个列表.请注意,文档大小有 1 MiB限制.
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.
这篇关于层次结构Firestore和子集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!