【发布时间】:2017-09-28 18:28:41
【问题描述】:
我正在尝试使用 Firebase Cloud 功能为 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 is not a function”。所以没有可用的“一次”方法 在 ref 上就像在 web api 中一样:
firebase.database().ref('...').once('value').then(function(snapshot) {
...
});
我的问题是:如何读取 index.js 中的现有数据库值?
【问题讨论】:
标签: javascript firebase push-notification firebase-realtime-database google-cloud-functions