I want a function to return what is in the 'user' collection. But due to async nature function is returning undefined. How can i wait till mongodb assigns value to the variable
function a(){
var m;
MongoClient.connect(URL).then( db => {
db.db('mydb').collection('user')
.find({}).toArray().then(result => {
m=result;
// return m wont help here
}).catch(log);
}).catch(log);
return m;
}
console.log(m);