13

在 Cloud Functions for 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}?谢谢

4

1 回答 1

19
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

于 2017-04-27T07:03:39.200 回答