Access db data in Cloud Functions for Firebase

我的梦境 提交于 2019-11-26 16:53:46

问题


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:


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



来源:https://stackoverflow.com/questions/43650472/access-db-data-in-cloud-functions-for-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!