I am trying to create a device to notify push devices for an iOS application using the Firebase Cloud features. I want to trigger an event whenever a new child is created in the database via the link '/ user-notification / {notificationRecipientUid} / {challengeId}'. Here is my index.js code:
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;
...
});
});
When a new password is added to the database at this location, I get this error: "TypeError: functions.database.ref (...). Once is not a function", in the Firebase console function logs. Thus, there is no one time ref method, as in the web api:
firebase.database().ref('...').once('value').then(function(snapshot) {
...
});
My question is: how to read the existing database value inside index.js?