hi here is the code im using
function get_last_chat_time(steamid){
if(!db_connect) {
return 0;
}
chat_db.aggregate(
[
{"$match":{"name":"chat-msg",steamid: steamid}},
{ "$sort" : { date : -1 } },
{"$limit" : 1}
]
).toArray(function(err, list){
if (err) {
console.log("Error loading history from DB: " + err);
} else {
var i = list.length-1;
var lasttime = Math.floor((new Date() - list[i].date)/1000);
console.log(Math.floor((new Date() - lasttime)/1000));//this works perfect
return lasttime;
}
});
}
console.log(get_last_chat_time(msg.steamid));// this is undefined
so basicly i want this function to return the value when i call function, when i do console log inside this toArray function its fine out side its not. I just dont understand how to get this to work