0

I'm using firebase rest API in my project. I have following data in firebase realtime database.

Users {
  -asgfhgkho {
     name:Rahul Vyas
    email: imrahulvyaas@gmail.com
   }
}
History {
-124lahsfaksfh {
  players {
   -asdfghjikjdlk {
     name:Rahul Vyas
     email: imrahulvyaas@gmail.com }
   }
  }
 }

Now my question is if I update the name property using patch. How the name will be reflected under History->players->{playerId}->name. How we can refer an user object in multiple different nodes. Note I'm using firebase rest API.

Thanks

Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256

1 Answers1

2

You will need to update those names yourself by writing code for it.

Since you must know the exact path to perform write to it, that means you'll typically:

  1. Perform a query to determine what nodes to update
  2. Perform an update for each, or a single multi-location update
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • but there could be 100's of location. Isn't there any way like we do in MySQL where user object is automatically fetched ? Like we set userId only at all other location and when we fetch from firebase it automatically fetch user object.. Is it possible ? – Rahul Vyas Jun 26 '20 at 06:13
  • Firebase does not support update queries. To write to a location, you must know the exact path to that location. Firebase also doesn't support server-side joins when reading data (which is what I think you're describing in your comment). But client-side joins are common, and not nearly as slow as many developers initially think due to the fact that Firebase pipelines the requests over a single connection. See https://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen Jun 26 '20 at 13:25
  • but on client side how we will keep track of user's all nodes ? – Rahul Vyas Jun 26 '20 at 15:37
  • can you explain point 1 in your answer ? Perform a query to determine what nodes to update - any pseudo code for this ? – Rahul Vyas Sep 07 '20 at 12:24
  • https://stackoverflow.com/questions/40589397/firebase-db-how-to-update-particular-value-of-child-in-firebase-database – Frank van Puffelen Sep 07 '20 at 13:36
  • thanks for the answer. It looks doable. I'm just wondering that is it possible to get all the nodes with their path using Firebase rest API ? Any hint for this ? I mean with reference to my question in the main post. – Rahul Vyas Sep 08 '20 at 08:54
  • Sure it is possible to [perform a query over the REST API](https://firebase.google.com/docs/database/rest/retrieve-data#section-rest-filtering. What problem do you have? Did you try anything yet? – Frank van Puffelen Sep 08 '20 at 13:26
  • No, I haven't tried it yet. Will let you know If I stuck somewhere. Thanks for helping me out. – Rahul Vyas Sep 09 '20 at 12:39