I have got a function like this,
const getCurrentDetails= async () => {
const currentDateTime = new Date(moment('00:00','HH:mm')
.tz('America/New_York')
.toISOString());
const currentDateDetail = await getDetailsForTimestamp(currentDateTime);
console.log("currentDateDetail: ",currentDateDetail) //prints PromiseProvider {}
if(currentDateDetail){
//do some stuff if details present
}
}
Even though I'm using await to resolve the promise before going to the next step, but still it logs PromiseProvider {} in the next step and the following condition check fails to validate properly.
Note that the same function works fine sometimes, but not consistent as I face the above-mentioned behavior many times, I'm using node 16, and here's the getDetailsForTimestamp function.
const getDetailsForTimestamp = async (currentTimeStamp) => {
const { db } = await database.getDb(process.env.DB_NAME);
if (db) {
return new Promise((resolve, reject) => {
db.collection(process.env.COLLECTION_NAME)
.findOne({ updatedAt: { $gte: currentTimeStamp } })
.then((res) => {
resolve(res);
})
.catch((err) => {
reject(err);
});
});
}
};