I have a node with the users list and a second node with the rating information for each user. I would like to loop within the users of the first node and for each one get the rating from the second node. The problem is that the loop doesn't wait for the second node to give the answer, therefore the array returned is always empty. I know I need to use await/async method but it's not working. Thanks for help
return admin.database().ref('/user').once('value').then(async(snap) => {
for(const userId of snap) {
admin.database().ref('/rating/' + userId.key).once('value').then(await (snap) =>{
var rating = snap.val();
array.push([userId.key, rating]);
}).catch(error => {
console.log("failed 1 " + error.code);
});
}
return array;
}).catch(error => {
console.log("failed 2 " + error.code);
});