【发布时间】:2020-11-07 22:42:08
【问题描述】:
我希望每次将新用户添加到匹配对象时执行一个函数,以增加匹配用户的数量。
exports.onCreateMatchmakingUser = functions.database.ref('/matchmaking/{$uid}').onCreate((snapshot, context) => {
const currentMatchmakingAmount = snapshot.ref.parent.child('matchmakingAmount').val();
return snapshot.ref.parent.update({matchmakingAmount: currentMatchmakingAmount+1});
});
我不想获取整个 matchmaking 对象然后获取数字,我只想要 matchmakingAmount。 snapshot.ref.parent 是否会造成问题(它是获取整个匹配对象,还是仅获取它的引用而不下载其数据)?如果是这样,我该如何解决这个问题并编写另一个函数来更新数字而无需不必要的下载?
【问题讨论】:
标签: node.js firebase-realtime-database google-cloud-functions