I have a block of code that looks like this:
async retrieveExportData() {
const exportStatistics: Object[] = [];
this.mongoRepositories.forEach( async (repository, key) => {
await repository.connect();
let queryResults = await repository.getData();
exportStatistics.push(...queryResults);
repository.close();
});
return exportStatistics;
}
this.mongoRepositories
is a Map<string, MongoRepo>
.
How can I properly return the complete exportStatistics
array? The current implementation leaves it empty at the end of the block.
EDIT: This question is distinct from the potential duplicate because of the differences in iterating over a Map compared to iterating over an Array. Updating the question title to reflect this distinction.