jeudi 26 juillet 2018

Firebase Multi path atomic update with child values?

I am succesfully updating my user's profile picture on their profile and on all of their reviews posted with this function:

export const storeUserProfileImage = (url) => {
    const { currentUser } = firebase.auth();

        firebase.database().ref(`/users/${currentUser.uid}/profilePic`)
        .update({ url });

        firebase.database().ref('reviews')
          .orderByChild('username')
          .equalTo('User3')
          .once('value', (snapshot) => {
            snapshot.forEach((child) => {
              child.ref.update({ profilePic: url });
            });
        });
  };

I am aware that I should be using an atomic update to do this so the data updates at the same time (in case a user leaves the app or something else goes wrong). I am confused on how I can accomplish this when querying over child values.

Any help or guidance would be greatly appreciated!

Cheers.




Aucun commentaire:

Enregistrer un commentaire