I am trying to console.log() after a forEach function using Async/Await or Callback(). But neither of them seems to be working. Here is the set of functions I am trying to execute.
addAirports = async(airportsJson, callBack) => {
await airportsJson.forEach( async(airport) => {
let db_find = await airportsModel.find({iata_code: airport.iata_code});
if (db_find[0] == null) {
airportsModel.insertMany(airport, function(error, docs) {});
console.log(airport)
}
});
callBack()
};
airportsUpdated = () => {
console.log("All airports are updated")
}
addAirports(airportsInput, airportsUpdated);
I have even tried using ".map". It would be great if someone can tell me how can I achieve a async execution using Async/Await or Callback but by NOT using timeout.