New to Firebase/FireStore and have no experience in NoSQL
.
While learning Android and as well as room by building an app for myself I realized that I need a real-time database solution. But I'm stuck at building the model structure.
This is the JSON format:
{
"published": "date",
"title": "This is the title",
"content": "This is the body",
"tags": [
"tag1", "tag2"
]
}
The problem is with the tags
many-to-many relation. Realized that FireStore can solve this with indexation but how do I structure the data with Collections and Documents? Can anyone explain in details?
Assuming that the snippet in your question is a
post
object, I recommend you a database schema that looks like this:Accordind to the official documentation regarding modelling data in a Cloud Firestore database:
So this is the best database structure I can think of for your app and as you can see, the
tags
property is not anarray
is amap
. This the best practice when it comes to this kind of objects. Please aslo see the offical documentation regarding working with arrays, lists, and sets.Edit 13 Aug 2018:
According to the updated documentation regarding array membership, now it is possible to filter data based on array values using
whereArrayContains()
method. A simple example would be:I guess you should use this
Post:
Tags