I have a while loop that loops from one date to the other date. And I want to submit some data to the firebase realtime database.
I want to submit, and wait till the result is back. And then go to the next iteration.
var loop = moment(startDate, 'MM-DD-YYYY').toDate();
var end = moment(endDate, 'MM-DD-YYYY').toDate();
while(loop <= end){
firebaseAdmin.database().ref('test/data').set({}).then(function(){
}).catch(function(error) {
});
const newDate = loop.setDate(loop.getDate() + 1);
loop = new Date(newDate);
}
The firebase database uses promises. How can I use them to go further in the loop when the insert is done. And how do I know that everything is done so I can return?