我试图从我的firebase读取所有数据 但我不能这样做
这是我的代码:
firebase.database().ref().child('users/').on('value',function(snapshot) {
window.alert(snapshot.val());
});
我的firebase看起来像这样:
"users":
{
"uid": {
"username": "AAA",
"email": "aaa@a.com"
},
"uid": {
"username": "ZZZ",
"email": "zzz@z.com"
}
}
更新
我在firebase中定义了我的安全性
{
"rules":{
"users":{
"$uid": {
// grants write access to the owner of this user account whose uid must exactly match the key ($uid)
".write": "auth !== null && auth.uid === $uid ",
//".write": "auth !== null && (auth.uid === $uid || auth.uid ==='0127a226-83ec-4eae-bbc7-53b81da10c0d')",
// grants read access to any user who is logged in with an email and password
".read": "auth !== null && auth.uid ===$uid "
//".read": "auth !== null && (auth.uid ===$uid || auth.uid ==='0127a226-83ec-4eae-bbc7-53b81da10c0d')"
//".validate": "newData.hasChildren(['full_name','uid','state_light'])"
}
}
} }
答案 0 :(得分:0)
从.child('users /')中删除无关/并将其格式化为
firebase.database().ref('users').on('value', function(snapshot) {
window.alert(snapshot.val());
});
此外,在您的firebase结构中,您不能拥有两个具有相同名称的键(uid)。