在 Cloud Functions for Firebase 中访问 db 数据 [英] Access db data in Cloud Functions for Firebase

本文介绍了在 Cloud Functions for Firebase 中访问 db 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Cloud Functions for Firebase 中,例如:

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}
})

如何在另一个节点读取数据,例如 /important/messages/{pushId}?谢谢

How to do I read data at another node, for example /important/messages/{pushId}? Thanks

推荐答案

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

这篇关于在 Cloud Functions for Firebase 中访问 db 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆