Sorting happens in mongo query, no longer in js.
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user