无法从firebase读取所有数据

时间:2016-05-29 13:40:19

标签: javascript firebase firebase-realtime-database

我试图从我的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'])"   
  }
}

} }

1 个答案:

答案 0 :(得分:0)

从.child('users /')中删除无关/并将其格式化为

firebase.database().ref('users').on('value', function(snapshot) {
  window.alert(snapshot.val());
});

此外,在您的firebase结构中,您不能拥有两个具有相同名称的键(uid)。