【发布时间】:2020-10-20 07:04:25
【问题描述】:
当我的数据结构中的计数变量发生变化时,我尝试触发 .onUpdate 函数。尽管计数变量更改仍然没有触发功能。 我的计数变量低于主实时数据库。
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Cloud Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
exports.cleanStorage=functions.database
.ref('/count')
.onUpdate((change,context)=>{
if(change.before.count===change.after.count){
return null;
}
const newCount=change.after.count-7;
return change.after.ref.update({count:newCount});
});
【问题讨论】:
-
您尝试
console.log和change.before.count看看它返回了什么?
标签: javascript node.js firebase firebase-realtime-database google-cloud-functions