I am trying to write a reusable function that doesn't return until it has resolved promise from a mongodb query. I can nearly achieve this using a IIFE function but seem unable to access the resolved value before I return from the function. In the snippet below i can print variable d to the console but i cant make it accessible outside the iffe and thus cannot return the result.
In the example below the first console.log returns the correct result but the second returns a pending promise. Any suggestions as to how to make this work or alternative methods will be much appreciated.
function getDNInfo (party){
var result;
result= (async () => { result = await mongo.findOne({DN:party.user_Number}, "BWUsers")
.then(
(d)=>{
console.log(d)
result=d;
}"
)}
)();
console.log(result)
return result;
}