我为节点团队创建了onCreate函数。它计算团队中的许多球员。它运作良好。这是代码:
exports.onPlayerToTeamAdd = functions.database.ref('/teams/{teamId}/players/{playerId}')
.onCreate((snapshot, context) => {
const count = snapshot.ref.parent.parent.child('count_players');
return count.transaction(count => {
return count + 1;
});
});
这是onDelete函数:
exports.onPlayerFromTeamDelete = functions.database.ref('/teams/{teamId}/players/{playerId}')
.onDelete((snapshot, context) => {
const count = snapshot.ref.parent.parent.child('count_players');
return count.transaction(count => {
return count - 1;
});
});
在删除整个团队之前,onDelete函数可以正常工作。当我删除球队时,它将使用“ count_players”值为-x(x是之前球队的球员人数)来创建同一球队的节点。
我的问题是:如何处理删除整个团队的状态?非常感谢。