Firestore数据建模文章和类别 [英] Firestore datamodelling articles and categories
问题描述
上下文:
我正在Angular中创建一种维基页面。 Wiki页面的总篇幅可能不会超过5000。
我想获得最有效的(页面加载)方式,但我认为我对此还太陌生,无法监督一种选择对另一种选择的影响。当然,我也想遵循惯例。
问题:
我在firestore中收藏了一些文章我要分类。文章应属于一个类别。一个类别可以属于一个类别(作为子类别)。
现在,首选哪种数据模型?为什么?
-
每个具有(参考数据类型的)属性的文章都引用类别文档?
-
类别文档具有对文章的引用数组?
Firestore-root
|
---类别(集合)
|
--- categoryId(文档)
|
--- name: Science //简单属性
|
---文章['articleId1','articleId2'等。(长数组)]
- 有些完全不同吗?
- 每个具有(参考数据类型的)属性的文章都引用类别文档吗?
只有文章可以属于一个类别时,此结构才有帮助。
Firestore-root
|
---文章(集合)
|
--- articleId(文档)
|
--- catoegory: Science //简单财产
使用对类别文档的引用。除此之外,要过滤文章,您可以简单地使用 where equal
调用。
< ol start = 2>
类别文档是否具有对文章的引用数组?
如果文章可以属于一个或多个类别,此结构将为您提供帮助。
Firestore-根
|
---文章(集合)
|
--- articleId(文档)
|
---分类:[科学,经济] //类型数组的属性
现在要过滤您的文章,您只需使用where array-contains
调用。
- 完全不同吗?
在构建Cloud Firestore数据库时,两种解决方案都得到了广泛使用,但是您应该选择哪种解决方案更适合您的应用程序用例。
Context:
I am creating a kind-of-wiki page in Angular. The wiki page would probably not get bigger than 5000 articles in total. I want to get the most efficient (pageload) way possible but I think I am too new to this to oversee the consequences of one option over the other. Of course I also would like to follow conventions.
Problem:
I have a collection of articles in firestore which I want to categorize. An article should belong to one category. A category can belong to one category (as a sub category).
Now, Which data-model is preferred? And why?
Every article having an attribute (of reference datatype) referring to the category document?
The category documents having an array of references to the articles?
Firestore-root
|
--- categories (collection)
|
--- categoryId (document)
|
--- name: "Science" //Simple property
|
--- articles ['articleId1', 'articleId2', etc.. (long array)]
- Something completely different?
- Every article having an attribute (of reference datatype) referring to the category document?
This structure will help you only if the an article can belong to a single category.
Firestore-root
|
--- articles (collection)
|
--- articleId (document)
|
--- catoegory: "Science" //Simple property
There is no need to use a reference to a category document. Beside that, to filter your articles, you can simple use a where equal
call.
- The category documents having an array of references to the articles?
This structure will help you if the an article can belong to one or more categories.
Firestore-root
|
--- articles (collection)
|
--- articleId (document)
|
--- catoegories: ["Science", "Economy"] //Property of type array
Now to filter your articles, you can simply use a where array-contains
call.
- Something completely different?
Both solutions are widely used when structuring a Cloud Firestore database, but you should choose which one is more appropriate to the use-case of your app.
这篇关于Firestore数据建模文章和类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!