1

For example, this is how I set data:

var usersRef = firebase.database().ref("userlist/"); usersRef.child(nickname).set({ userid: id, email: email, }); 

What should I do if I later on want to get email given the nickname? Why can't I do something like this:

const email =usersRef.child(nickname).child(email); 

2 Answers 2

2

To get the email you need to do the following:

 var ref = firebase.database().ref("userlist").child(nickname); ref.on("value", function(snapshot) { let emails=snapshot.val().email; console.log(email); }); }); 

You need to reference the location and then attach a listener to it to be able to retrieve the child values like email and id

Sign up to request clarification or add additional context in comments.

Comments

1

The email constant that you set does not point to an email rather it points to a firebase database reference.

To get the value of email, you listen to the reference and the value is equal to what is returned.

ref.child(nickname).child("email").on("value", function(snapshot) { const email = snapshot.val(); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.