获取父uid数据

时间:2018-06-05 06:06:11

标签: firebase firebase-realtime-database ionic3 angularfire2

我试图获取UID数据。

以下是我的Firebase数据库结构

enter image description here

和规则

enter image description here

我的代码在.ts

firebase.database().ref('/appointment/').orderByChild('keys').equalTo(this.user.$key).once('value').then(snapshot => {
  snapshot.forEach(function(child) {
    console.log(child.key);
  });
})

但我在控制台中得到了这个

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "keys" at /appointment to your security rules for better performance 

请知道我做错了什么?我怎么能得到uid ??

1 个答案:

答案 0 :(得分:1)

您在数据库中没有名为key的孩子,这就是您所拥有的:

appointment
        userid
            randomKey
                 almt:...
                 gr:...

如果要检索当前用户ID,请执行以下操作:

 var user = firebase.auth().currentUser;
 var uid=user.uid;

如果您只想从数据库中检索它,请执行以下操作:

firebase.database().ref('/appointment/').once('value').then(snapshot => {
snapshot.forEach(function(child) {
  console.log(child.key);
 });
})

这将在appointment的直接子项内循环,child.key将检索uid