firebase database ref update method is not working

Viewed 2682

To update the keys and values in my firebase data from javascript , When I do this : -

ref.update({"key" : "value" }) ;

It works fine and updates the data in my firebase database .


But when I do this :-

    data = {} ;
    email = "mymail"
    pass="pass"
    data[email] = pass
    ref.update(data);

Does't work and when I see the database nothing would have been updated. How to fix this ?

EDIT 1:-

If I directly give , ref.update({email , pass}) , what happens is it updates the data in the database but instead of the string in the email it just stores 'email' as the key in the database . Any fix ?

1 Answers

Are you sure you don't miss the / separators?? see the following example from https://firebase.google.com/docs/database/web/read-and-write

var updates = {};
updates['/posts/' + newPostKey] = postData;
updates['/user-posts/' + uid + '/' + newPostKey] = postData;

return firebase.database().ref().update(updates);
Related