async function myAsyncFunc(monthlyPeriodsArr, monthly_periods_results_arr, monthly_periods_plot_arr)
{
for (let index = 0; index < monthlyPeriodsArr.length; index++) {
const elementArr = monthlyPeriodsArr[index];
console.log(index+": element: "+elementArr);
var PromiseResult = await
CallMongoDBWithPeriodResolution.executeMongoDBAggregateQueryDates(elementArr[0], elementArr[1]);
console.log("PR: "+PromiseResult);
console.log("PromiseResult: "+PromiseResult.then((result) => {
console.log("Success", result);
}).catch((error) => {
console.log("Error", error);
}));
}
}
In the above code CallMongoDBWithPeriodResolution.executeMongoDBAggregateQueryDates(start_date, end_date) returns undefined.
But the query works in the function callback that connects to the database.
I can do any and all things with the data in the callback but returning an array or a promise always returns undefined. How can I correct this?
I have tried promises and await and async. I have been attempting regular functions while waiting for the callback.
Returning myresultsArray that is visible inside the callback returns undefined in all cases.
Cheers,
Daniel