15

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

1 Answer 1

20
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

Sign up to request clarification or add additional context in comments.

2 Comments

How can you read the remaining data on the node /messages/{pushId}/original!? Example if you wanted to read the remaining data on the path /messages/{pushId}/
event.data.val() will give you the data in the /messages/{pushId}/original node

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.