Sorting happens in mongo query, no longer in js.

This commit is contained in:
2021-02-17 19:20:52 +01:00
parent c98ccbc3f0
commit 38eb98e68b

View File

@@ -172,7 +172,8 @@ const latest = () => {
}; };
// lottery - byDate // lottery - byDate
const groupByDate = (includeWines = false, sort = "desc") => { const groupByDate = (includeWines = false, sort = "asc") => {
const sortDirection = sort == "asc" ? -1 : 1;
const query = [ const query = [
{ {
$unwind: "$wins" $unwind: "$wins"
@@ -198,7 +199,7 @@ const groupByDate = (includeWines = false, sort = "desc") => {
}, },
{ {
$sort: { $sort: {
_id: -1 date: sortDirection
} }
} }
]; ];
@@ -214,7 +215,7 @@ const groupByDate = (includeWines = false, sort = "desc") => {
}); });
} }
return Winner.aggregate(query).then(lotteries => (sort != "asc" ? lotteries : lotteries.reverse())); return Winner.aggregate(query);
}; };
// highscore - byColor // highscore - byColor