I am stuck on promise resolution, can anyone explain to me how to store the promise result in a variable? I am working with mongoDB and I want to get some data from it. here is my example.
const checkRelated = new Promise((resolve, reject) => {
return RelatedProducts.find({
parent_id: { $in: product_id.split(',') },
})
.then((res) => reject(res))
.catch(err => reject(err))
})
after getting the data I want to do some validation. For example.
if(checkRelated.length > 0) {
do smth....
}
but to my surprise I get "promise {pending}"