How can I get a return after I loop through all my firebase results to properly finish my cloud function?
var count = 0;
return ref.child('/records').once('value').then(snap=>{
snap.forEach(snapChild=>{
var ucName = ${snapChild.val().name.toUpperCase();
var update = {'name':ucName);
ref.child(`/records/${snapChild.key}`).update(update).then(()=>{
count++;
res.write(`<p>${ucName} updated</p>`);
});
})
}).then(()=>{
return res.end(`<p>end of list (${count} records)</p>`);
})
It actually does what it is supposed to do but the counter stays at 0 and I get an error 'write after end' - I guess due to the missing return from forEach.
constandlet?countis a variable that is changing of value due tocount++, it is alet.ucNameandupdatein other hand do not get modified, they areconst. Good luck with theses techs :)