How can i save a variable from async function .find from mongodb? Inside the function console.log its working (prints the right value) and outside the function it is undefined.
var list;
MongoClient.connect(uri, function(err, db) {
var dbc = db.db("chat");
dbc.collection("chat_messages").find({user1: data.from, user2: data.to}).toArray(function (err, result){
console.log(result[0].msgs); <---- here its working
list = result[0].msgs;
});
db.close();
});
console.log(list); <---- here its not working