繁体   English   中英

在Firestore中存储标签的最有效方法是什么?

[英]What is the most efficient way to store tags in Firestore?

NoSQL Firestore没有表,什么是最好的标记方式,只需将多个标记存储在数组中?

NoSQL Firestore没有表。

没错,数据库采用JSON格式。

仅将多个标签存储在数组中,最好的标记方法是什么?

根据您的应用程序的用例,您可以选择两种方法。 如果标签的类型为String,则可以将此文字字符串存储在数组中。 这将是第一种方法,数据库架构可能如下所示:

Firestore-root
    |
    --- questions (collections)
          |
          --- questionId (document)
                 |
                 --- questionId: "02cubnmO1wqyz6yKg571"
                 |
                 --- title: "Question Title"
                 |
                 --- tags ["History", "Geography"]

如您所见,我以一个问题集合为例,其中每个文档都有一个标签数组。

如果您需要有关标签的更多详细信息,第二种方法是为每个标签创建一个对象,并将该标签对象存储在集合中。 在问题文档中,您只需要将标记的ID也存储在数组中,如以下模式所示:

Firestore-root
    |
    --- questions (collections)
    |     |
    |     --- questionId (document)
    |            |
    |            --- questionId: "02cubnmO1wqyz6yKg571"
    |            |
    |            --- title: "Question Title"
    |            |
    |            --- tags ["tagId", "tagId"]
    |
    --- tags (collections)
          |
          --- tagId (document)
          |     |
          |     --- tagId: "yR8iLzdBdylFkSzg1k4K"
          |     |
          |     --- tagName: "History"
          |     |
          |     --- //Other tag properties
          |
          --- tagId (document)
                |
                --- tagId: "tUjKPoq2dylFkSzg9cFg"
                |
                --- tagName: "Geography"
                |
                --- //Other tag properties

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM