I need to populate array with values from DB and only then return it, so how can i make this Synchronous
var convs = Array; User.find({token: token}).first(function(err, user) { ConversationData.find({user_id: 1}).each().forEach(function(convData) { ConversationData.count({conversation_id: convData.conversation_id}, function(err, count) { if(count == 2) { var user2; console.log(convData.user_id); ConversationData.find({user_id: 2, conversation_id: convData.conversation_id}).first(function(err, usr) { user2 = usr; }); Message.find({conversation: convData.conversation_id}, [ "createdAt", "Z" ]).first(function(err, msg){ convs[convData.id].conversation = convData.id; convs[convData.id].lastMessage = msg.content; convs[convData.id].lastMessageDate = msg.createdAt; convs[convData.id].title = user2.name + " " + user2.name; convs[convData.id].avatar = user2.avatar; }); } else { console.log('COUNT = ' + count); } }); }); console.log(convs);