this doubt is about promises. I need to add documents of the subcollection 'bar' into array intialized outside of the block
...
foo.bars = new Array<IBar>();
let manyBars = documentRef.collection('bar').listDocuments();
(await manyBars).forEach( barItem => {
barItem.get().then(barDocument => {
let bar: IBar = JSON.parse(JSON.stringify(barDocument.data()));
if (foo.bars !== null) {
foo.bars.push(bar);
console.log('in');
}
});
});
console.log('out');
My console.log() prints firts 'out' and then 'in'. What am I doing wrong? forEach method has "await".