app get archive function req res db collection data find type events m

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
app.get('/archive/', function(req, res) {
db.collection("data").find({type: "events", marks: "zenitbilet"}).toArray(function (err, zenitArchive) {
var eventIndex = 0;
async.whilst(
function () { return eventIndex < zenitArchive.length; },
function (callback) {
db.collection("data").findOne({type: "teams", _id: zenitArchive[eventIndex].team1}, function(err, teamName) {
zenitArchive[eventIndex]['team1_name'] = teamName.name;
db.collection("data").findOne({type: "teams", _id: zenitArchive[eventIndex].team2}, function(err, teamName) {
zenitArchive[eventIndex]['team2_name'] = teamName.name;
eventIndex++;
callback(err, null);
});
});
},
function (err) {
console.log(zenitArchive);
res.render("archive", {
archive: zenitArchive,
MEDIA_HOST: process.env.MEDIA_HOST
});
}
);
});
});