我正在尝试在 Firebase 云函数中获取我的 Firebase 数据库的特定键值。
键值在节点下。 "fcmToken"/"receiverUid"其中receiverUid是唯一的Key值。
admin
.database()
.ref(/fcmToken/${receiverUid})
.once("value")
.then(snapshot => {
var getInstanceIdPromise = snapshot.key;
}).catch(e => {
console.log(e);
})
ESlint 不断给我返回或捕获错误。
我应该如何修复此代码以便从 fcmToken/{variable}/key value 获取值?
最佳答案
如果您的数据库如下所示(fcmToken/{variable}/key value
):
fcmToken
uid
tokenName : food
然后执行以下操作来获取 food
的值:
admin
.database()
.ref(/fcmToken/${receiverUid})
.once("value")
.then(snapshot => {
var getInstanceIdPromise = snapshot.tokenName;
}).catch(e => {
console.log(e);
})
在你的情况下key
是 datasnapshot
的属性(property)它为您提供数据库中的当前位置,即 ${receiverUid}
的值.
来自文档:
The key (last part of the path) of the location of this DataSnapshot.
关于javascript - 如何使用firebase云函数从firebase数据库检索子节点的键值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54859742/