Consider the following firebase tree where I have a primary node called users
that holds name, avatar, email and other user stuff that I use and are replied across other nodes.
I have another primary node called games
. One user can play many games alone or with other players.
If a user er09gju34900jf23 decides to update its profile, how can I look to all my database where I have this id and update all paths at once?
{
users: {
er09gju34900jf23: { // Authenticated User ID
avatar: '',
email: '',
name: '',
// other user profile data
}
},
games: {
er09gju34900jf23: { // Authenticated User ID
a2w4053g9043if092: { // Game Random Generate Game ID (1)
// other data
players: {
er09gju34900jf23: {
avatar: '',
email: '',
name: '',
// other user profile data
},
// other players
}
},
bewrpgkrthg96k059h: { // Game Random Generate Game ID (2)
// other data
players: {
er09gju34900jf23: {
avatar: '',
email: '',
name: '',
// other user profile data
},
// other players
}
}
}
}
}
For this tree, how can I find out that er09gju34900jf23 is a player in a2w4053g9043if092 and bewrpgkrthg96k059h games and then update its data, like below:
/users/er09gju34900jf23 = {avatar, email, name}
/games/er09gju34900jf23/a2w4053g9043if092/players/er09gju34900jf23 = {avatar, email, name}
/games/er09gju34900jf23/bewrpgkrthg96k059h/players/er09gju34900jf23 = {avatar, email, name}