我正在使用Http请求触发云功能。 问题是检索我拥有的整个对象列表,而没有事件然后循环它们。 该列表位于 account / userId 节点下。
这是我使用的,但我什么都没得到:
return admin.database().ref('/account/' + userId).once('value').then(function (snap) {
let data = snap.val();
}
答案 0 :(得分:2)
如果没有看到你的数据库结构,那么写一个答案并且100%肯定它是正确的答案有点困难,但以下应该可以解决这个问题:
return admin.database().ref('/account/' + userId).once('value').then(function (snap)
snap.forEach(function(child) {
const childKey = child.key; // <- here you get the key of each child of the '/account/' + userId node
console.log(childKey);
const childVal = child.val(); // <- and here you get the values of these children as JavaScript objects
console.log(childVal);
});
});
如果这不完全符合您的要求,请使用您的数据库结构和Cloud功能的完整代码更新您的问题。