In Cloud Functions for Firebase, for example:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
//how to access data at another node, for example
//important/messages/{pushId}
})
How to do I read data at another node, for example /important/messages/{pushId}
? Thanks
Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your JavaScript or TypeScript code is stored in Google's cloud and runs in a managed environment.
In a typical lifecycle, a Firebase Realtime Database function does the following: Waits for changes to a particular database location. Triggers when an event occurs and performs its tasks. Receives a data object that contains a snapshot of the data stored in the specified document.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original').onWrite(event => {
const getSomethingPromise = admin.database().ref(`/important/messages/{pushId}`).once('value');
return getSomethingPromise.then(results => {
const somethingSnapshot = results[0];
// Do something with the snapshot
})
})
Check this example for instance: https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With