0

I want to update multiple nodes(based on query) on Firebase. Here's the structure of the database. Firebase Database Structure Suppose, I'm updating the user information for the user "user003". As soon as I update the name and image of the user "user003", I want to search the database whose whose are friends with user003, friends are denoted as friend_list on the database. SO, upon updating the user003 information, I want to update the user003's information on the friend_list too. Hope you understand what I wanted to do. Here's the illustration of the update: Upon update. I'm using the following code to update the user003 information to the Firebase Database:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference()
.child(Commonx.USER_INFORMATION);

HashMap<String, Object> userMap = new HashMap<>();

userMap.put("name", fullNameEditText.getText().toString());
userMap.put("image", imageEditText.getText().toString());
userMap.put("image", myUrl);
ref.child(Commonx.loggedUser.getUid()).updateChildren(userMap);

Here Commonx.USER_INFORMATION= "User information" on the database. And, by Commonx.loggedUser.getUid()= the userid of the database.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Ovee
  • 1
  • 2
  • i suggest to use Firebase function for something like this cause from above database structure. It is hard to find who is friends with user3 – Ashish Oct 04 '19 at 11:19
  • @Ashish I can keep the logged user data and just match with all the user's friend list, if the data matches then I can just update. The logic is simple but I don't know how to do in Firebase – Ovee Oct 04 '19 at 11:32
  • do you have user friendlist of current logged in user ? – Ashish Oct 04 '19 at 11:48
  • Sounds like a clear use-case, you'll need to perform an update for each user (or a single multi-location update across all of them). What problem do you have? If you're just looking for info on approaches, have a look at my answer here: https://stackoverflow.com/questions/30693785/how-to-write-denormalized-data-in-firebase – Frank van Puffelen Oct 05 '19 at 14:21

0 Answers0