【发布时间】:2019-06-22 20:00:23
【问题描述】:
我有一个 Cloud Functions,它会在我的实时数据库中的某个值发生更改时触发。之后我需要从数据库中读取另一个值。
我在网上搜索并找到了一种解决方案。它起作用了:只要/ID/temp_id 处的值发生变化,该函数就会触发,但读取/ID/I 处的值需要额外的 5 秒。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.getID = functions.database.ref("/ID/temp_id").onUpdate((change, context)=>{ //triggers the function when value "temp_id" changes
const tempID = change.after.val();
const i_snap = admin.database().ref("/ID/i").once("value", function(snapshot){ //read the value at "/ID/i" from the databse
const i = snapshot.val();
})
})
有什么方法可以更快地读取/ID/I 的值吗?
【问题讨论】:
标签: javascript firebase-realtime-database google-cloud-functions