Доступ к данным БД в облачных функциях для Firebase

В облачных функциях для Firebase, например:

exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
    .onWrite(event => {
    //how to access data at another node, for example 
    //important/messages/{pushId}
})

Как мне прочитать данные на другом узле, например /important/messages/{pushId}? Спасибо

1 ответ

Решение
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
    })
})

Проверьте этот пример, например: https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js