[英]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.