Firebase 获取父uid数据

Firebase 获取父uid数据,firebase,firebase-realtime-database,ionic3,angularfire2,Firebase,Firebase Realtime Database,Ionic3,Angularfire2,我正在尝试获取UID数据 以下是我的Firebase数据库结构 规则呢 我的代码是.ts firebase.database().ref('/appointment/').orderByChild('keys').equalTo(this.user.$key).once('value').then(snapshot => { snapshot.forEach(function(child) { console.log(child.key); }); }) 但我在控制台

我正在尝试获取UID数据

以下是我的Firebase数据库结构

规则呢

我的代码是.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???

您在数据库中没有名为
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);
 });
})
如果只想从数据库中检索,请执行以下操作:

 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

谢谢Peter,但我想检索所有作为admin的userid,而不是当前的userid。我该怎么做呢?试试第二种选择,我在回答中说了谢谢彼得,这很有效。。你能再帮我一次吗??如果我执行
snapshot.forEach(函数(child){child.forEach(函数(granten){console.log(granter.key);console.log(granter.val();});console.log(child.key);}),如何显示用户ID和数据在前视图中??