【发布时间】:2020-06-21 23:59:21
【问题描述】:
每小时,我希望我的 firebase 函数查看我的数据库,读取一个值,从这个旧值计算一个新值,然后在数据库中更新它。我无法访问数据的快照。具体来说,
exports.scheduledFunction = functions.pubsub.schedule('every 1 hour').onRun((context) => {
const ref = functions.database.ref('/users/test_user/commutes');
ref.once('value',function(snapshot) {
// do new calculation here
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
return null;
});
我收到一个:functions: TypeError: ref.once is not a function 错误。
如何访问我的 firebase 实时数据库中的值并通过 Firebase 函数更新它?
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions