The NoSQL Firestore has no table, what will be the best way for tagging, just store multiple tags in an array?
The NoSQL Firestore has no table.
That's right, the database is in a JSON format.
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. 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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With