0

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}
lordshark
  • 83
  • 9

1 Answers1

0

I would recommend not replicating each user's full data under each game. Instead just replicate their UID under each game and then look up the information for each user from their /users/$uid node.

I'd also recommend:

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks Frank! Due to two of these links that I decided to adopt the structure described in my question. I am going to do a second read of theses recomendations. I comment again after reading. – lordshark Apr 28 '17 at 22:14