考虑以下firebase结构:
{
"users": {
"h7iStd4QvAYWh9xPbsiFuByDd1j1" : {
"email" : "jobs@apple.com",
"name" : "Steve Jobs",
"rank" : 0
},
"wkA0DrJs9wdBlfAkJuKIrnhNzyq2" : {
"email" : "gates@microsoft.com",
"name" : "Bill Gates",
"rank" : 0
}
}
}
和这个数据检索:
const email = 'jobs@apple.com';
firebase.database().ref('users').equalTo(email, 'email').once('value')
.then((snapshot) => {
console.log(email, snapshot.key, snapshot.val());
// snapshot.val() always returns null
})
.catch((error) => {
console.error(error);
});
为什么snapshot.val()
返回null?获取有关史蒂夫乔布斯数据的整个对象的正确方法是什么,h7iStd4QvAYWh9xPbsiFuByDd1j1
密钥的孩子?
答案 0 :(得分:2)
请改为尝试:
firebase.database().ref('users').orderByChild('email').equalTo(email).once('value')