简体   繁体   English

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

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

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

The NoSQL Firestore has no table. NoSQL Firestore没有表。

That's right, the database is in a JSON format. 没错,数据库采用JSON格式。

What will be the best way for tagging, just store multiple tags in array? 仅将多个标签存储在数组中,最好的标记方法是什么?

According to the use case of your app, you can choose between two approaches. 根据您的应用程序的用例,您可以选择两种方法。 If your tags are of type String, then you can store this literal strings in an array. 如果标签的类型为String,则可以将此文字字符串存储在数组中。 This would be the first approach and the database schema might look like this: 这将是第一种方法,数据库架构可能如下所示:

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

As you can see, I took as an example a collection of questions in which each document has an array of tags. 如您所见,我以一个问题集合为例,其中每个文档都有一个标签数组。

If you need more details about a tag, the second approach would be to create an object for each tag and store this tag objects in a collection. 如果您需要有关标签的更多详细信息,第二种方法是为每个标签创建一个对象,并将该标签对象存储在集合中。 In the question document, you'll only need to store the ids of the tags also in an array, as in the following schema: 在问题文档中,您只需要将标记的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.

相关问题 将数据存储到Firebase中的多个引用的最有效方法是什么? - What's the most efficient way to store data to multiple refs in firebase? 在Firebase Firestore中查询帖子的最有效方法 - Most Efficient Way To Query Firebase Firestore For Posts "Firestore - 如何以最有效的方式构建数据?" - Firestore - How to structure data the most efficient way? 对于此用例,最有效的 Firestore 模型是什么? - What is the most efficient firestore model for this use case? 在 Cloud Firestore 中处理大型集合的过滤和排序的最有效和可扩展的方法是什么? - What's the most efficient and scalable way to handle filtering and sorting of a large collection in cloud firestore? Firestore:在聊天中列出消息的有效方法是什么? - Firestore: What is the efficient way to list messages in chat? 将数据从RecyclerView保存到Firestore(以及多个片段)的最有效方法 - Most efficient way of saving data from RecyclerView into Firestore (and with multiple fragments) 从 Firestore 中的多个子集合的多个子集合中获取所有文档的最有效方法是什么? - What is the most efficient way to get all documents from multiple sub-collections of multiple sub-collections in Firestore? 在Firebase DB中存储布尔值的最有效方法 - Most efficient way to store boolean values in Firebase DB 在 Firestore 上存储 ToDo 的最佳方式是什么? - What is the best way to store a ToDo on Firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM