【发布时间】:2017-09-25 23:47:29
【问题描述】:
在 Cloud Functions for Firebase 中,例如:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
//how to write data at another node and return promise?
return admin.database().ref(`/abc/1234`).update({a:1}); //is this the correct way?
})
在https://firebase.google.com/docs/functions/get-started,它说
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
但在https://firebase.google.com/docs/database/admin/save-data 中,api 正在使用回调。我可以知道如何正确设置/更新 firebase 函数中的数据吗?该代码将起作用,但我不确定我是否正确执行此操作,或者它是否是推荐的方式。谢谢。
【问题讨论】:
-
Firebase SDK 支持承诺和回调。有关更多详细信息,请参阅this blog post。简而言之——你上面写的应该可以工作!
标签: javascript firebase firebase-realtime-database google-cloud-functions