gpt4 book ai didi

firebase - 在 Cloud Functions for Firebase 中访问数据库数据

转载 作者:行者123 更新时间:2023-12-04 01:46:22 24 4
gpt4 key购买 nike

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

最佳答案

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

关于firebase - 在 Cloud Functions for Firebase 中访问数据库数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43650472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com