I'm on a react-native project where I'm querying firebase to get some data from Firebase realtime database. However I receive my required output by below code.
getData = (email) => {
let usersRef = firebase.database().ref('users');
usersRef.orderByChild('emailAddress').equalTo(email).on("value", (snapshot) => {
let data = snapshot.val();
console.log(data);
console.log(data.emailAddress);
});
}
But unexpectedly I get the output for second log as undefined
.
Problem
I cannot read the value of emailAddress
. I don't understand why. Below is my database structure.
I was missing foreEach function since it returns proto as well.
getData = (email) => {
let usersRef = firebase.database().ref('users');
usersRef.orderByChild('emailAddress').equalTo(email).on("value", (snapshot) => {
snapshot.forEach((snap) => {
console.log(snap.val().emailAddress);
})
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.