Я новичок в облачных функциях (узел js с машинописью).Я использую его для получения данных из базы данных Firebase (как показано ниже).Но не в состоянии выяснить, как ждать, пока цикл forEach будет повторяться полностью, и использовать этот результат.
const reference = admin.database().ref('/books')
var path_key:string
var total_count:number = 0
reference .forEach(function (snapshot) {
path_key= snapshot(key).val()
ref_users_advance_bookings.child(path_key)
.once('value').then((snapshot2)=>{
if(condidtion met){
return response.send("failed")
}
else{
total_count++
}
)}
return true
})
// i want to use total_count value here
return response.send("count :"+total_count) // but every time I gets 0, as it get executed before forEach has ended
)}