【发布时间】:2020-05-12 13:51:31
【问题描述】:
假设我有如下结构的数据库节点:每个用户设置他/她偏好的用户名,并且由 Firebase auth 分配的他/她的 UID 记录在用户名下。
"uid_match":
{
"username_1" : {
"uid" : "firebase_uid_1"
},
"username_2" : {
"uid" : "firebase_uid_1"
}
我正在尝试编写代码以通过 firebase uid 提取用户名。它将查找某个 firebase uid 并返回用户名,该用户名具有自己的 URL。
以下是我编写的部分代码,但它返回的是“/uid_match”,而不是“/username_1”或“/username_2”。
let ref=firebase.database.ref('/uid_match');
let user=firebase.auth().currentUser;
ref.orderByChild('uid').equalTo(user.uid).once('value', function(snapshot) {
window.location.href='/'+snapshot.key;
})
问题:提取“username_1”或“username_2”而不是“uid_match”的正确查询代码是什么?提前非常感谢。
【问题讨论】:
标签: javascript firebase firebase-realtime-database