javascript - Firebase云函数,获取最后添加的子项

标签 javascript firebase google-cloud-functions

我正在尝试在云函数中获取最后添加的子项。这是代码。我想问是否有任何函数或查询可用于获取最后添加的子项。 这是我的代码:

exports.makeUppercase = functions.database.ref('aaa-fff/searchIndex')
    .onWrite(event => {
   // all records after the last continue to invoke this function
   console.log(event.data.val());
   console.log(event.data.numChildren());
});
PS。我不想让 child 循环播放。

最佳答案

我不太确定您的用例是什么,但这将为您提供最后一个 child :

exports.makeUppercase = functions.database.ref('aaa-fff/searchIndex')
    .onWrite((change, context) => {
   // all records after the last continue to invoke this function
   var lastChild;
   change.after.forEach(function(child) {
       lastChild = child;
   });
   console.log(lastChild.val());
});

关于javascript - Firebase云函数,获取最后添加的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44206275/

相关文章:

javascript - 在哪里安全地存储 javascript 发送网格 api key ?

javascript - “函数返回未定义的、预期的 promise 或值”,函数只打印日志

javascript - 可变的最佳实践 |不可变对象(immutable对象)

Javascript jquery 帮助 w/for 循环按钮

firebase - 使用规则保护 Firestore 数据库。检查身份验证。够了吗?

android - 我可以自定义 firebase OTP 数字(默认 6 到 4)吗?

mysql - Google Cloud Functions 中 Api 设计的最佳方法?

google-cloud-functions - GCP 云功能何时确认发布/订阅消息?

javascript - Asp 按钮禁用 asp 日历上的月份更改

javascript - 如何在 jQuery Mobile 中的选择框中禁用下拉菜单的打开