In this code, I am first deleting a collection and then inserting data into it. But I realised that the insertMany is called halfway of the deleteMany so the data is all messed up. How do I force insertMany to be called after deleteMany fully does its job?
return new Promise(async (resolve, reject) => {
try {
try {
//delete old data
await Rewards.deleteMany({});
//post the data into the Rewards schema here
let query = await Rewards.insertMany(data);
resolve(query);
} catch (e) {
console.log("e", e);
}
} catch (e) {
reject(e);
}
})
}```