Código HTML:
socket.on('Mongo_files', function(){ var query = {'IdDrive':currentPlayer.IdDrive}; files.find(query).then(function(bo){ var result = normalizeCursor(bo); for (var i =0; i< result.length; i++) { routes.count({Lot:result[i].Lot ,IdStatus:null}, function(err,res){ console.log(res) }); } return Promise.all(result); }).then(function(result) { if (result==null) { SONORA(currentPlayer.Id,'Mongo_files',[0,"No hay rutas pendientes"]) } else { SONORA(currentPlayer.Id,'Mongo_files',[1,result]) } }) ; });