【问题标题】:Get parent uid data获取父 uid 数据
【发布时间】:2018-11-14 12:39:27
【问题描述】:

我正在尝试获取 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??

【问题讨论】:

    标签: firebase firebase-realtime-database ionic3 angularfire2


    【解决方案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

    【讨论】:

    • 感谢彼得,但我想以管理员身份检索所有用户 ID,而不是当前用户 ID。我该怎么做??
    • 试试第二个选项,我给了答案
    • 谢谢彼得,它有效.. 你能再帮我一次吗?如果我在前视图中使用snapshot.forEach(function(child) { child.forEach(function(grandchild) { console.log(grandchild.key); console.log(grandchild.val()); }); console.log(child.key); }); }),如何显示用户 ID 和数据??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 2015-05-09
    • 2021-04-10
    • 2019-06-04
    • 2012-05-13
    • 1970-01-01
    • 2021-02-09
    相关资源
    最近更新 更多