通过我的代码,我可以计算Firebase Realtime数据库中的文档数,但是我需要它们为每个groupId都有一个计数器,然后将其保存在每个groupId的不同路径中。
这是我正在计算的文件路径
消息/ {groupId}
我想将其保存在这里,每个计数器都有自己的groupId
totalmessages / groupId
exports.messageCounter = functions.database.ref('/messages/{groupId}').onWrite((change, context) => {
const data = change.after.val();
const group = data.groupId;
const count = Object.keys(data).length;
return admin.database().ref('totalmessages/'+group).child('_count').set(count);
});
当前代码返回:
他还用新数据覆盖“ _Count”,并且不创建几棵树。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句