Actually yes you have to do that. If you eg have users in there, you'll end up with something like this:
{
users: {
"user-0": {
"firstName": "Max",
"lastName": "Powers"
},
"user-1": {
"firstName": "Maxime",
"lastName": "Powers"
}
}
}
Now, from your apps perspective, the user is signed in and therefore the app knows the user-id. With this information you can subscribe to changes on the whole user.
If you go one step further and nest eg rides below each user, as a mobility app will do, you end up with a JSON like this:
{
users: {
"user-0": {
"rides": {
"ride-0": {
"updated_at": ...
}
}
}
}
}
When in this mobility app a user creates a ride, the app will will receive a ride-id from the backend which it can use to subscribe to the related ride in firebase. The path would be eg users/<user-id>/rides/<ride-id>
. The app will then get updates each time this ride is updted in the realtime database.
In the end each user has multiple subscriptions. We do it for a couple of years this way and it works quite well
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.