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