0

I have users that have friends. Those friends are linked by some data when they accept the request. The data tree looks like this;

friends
    [uid] // the users uid
        [uid] // the uid of the friend
            status: 'friends'
            username: 'UserName1'

This is top-level data used to quickly present to the user the names of their friends, rather than each one requiring an additional query to fetch the name.

The problem comes with updating the username. If UserName1 wants to change their username, this would be one of the places it needs to be updated. The other locations are not as deeply nested so not as much of an issue.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Alex
  • 2,003
  • 4
  • 19
  • 30
  • What precisely is the issue here? Did you try writing the code and got stuck? Or don't you know how to go about this to begin with. For the latter, have a look at my answer here about common strategies to update fanned-out/denormalized/duplicated data: https://stackoverflow.com/questions/30693785/how-to-write-denormalized-data-in-firebase – Frank van Puffelen Jun 22 '18 at 16:34
  • Yeah, so i think i have to loop through friends to get a list of ID's to update before running the update. i was trying to establish if there was a better approach without a pre-setting query to get the data to update – Alex Jun 22 '18 at 18:07
  • Firebase does not support update queries of the type you have in SQL (`UPDATE tblUsers SET status = 'yes' WHERE username = 'Alex'`). You will always have to know the path of each individual node you want to update. – Frank van Puffelen Jun 22 '18 at 18:16

0 Answers0