我正在尝试创建设备来使用Firebase函数为iOS应用程序创建设备推送通知。每当在引用'/user-notifications/{notificationRecipientUid}/{challengeId}'.的数据库中创建新的子对象时,我希望触发一个事件。以下是我的index.js代码:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendWinLoseOrTieNotification = functions.database.ref('/user-notifications/{notificationRecipientUid}/{challengeId}').onWrite(event => {
...
const challengeId = event.params.challengeId;
functions.database.ref('/challenges/' + challengeId).once('value').then(function(snapshot) {
const challengerUid = snapshot.val().challengerUid;
...
});
});当在该位置的数据库中添加一个新的子元素时,我会在Firebase控制台的函数日志中得到一个错误,"TypeError: functions.database.ref(.).once不是一个函数“。因此,在ref上没有“一次性”方法,比如在web中:
firebase.database().ref('...').once('value').then(function(snapshot) { ... });
我的问题是:如何读取index.js中现有的数据库值?
发布于 2017-05-01 10:48:37
好的,解决方案是使用admin而不是防火墙,如下所示:
admin.database().ref('...').once('value').then(function(snapshot) {
...
});https://stackoverflow.com/questions/43717434
复制相似问题