From e4de0347ad82d5c972d128567603e5ca588fac26 Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Wed, 9 Nov 2022 17:34:51 +0100 Subject: [PATCH] Return stations sorted --- server/Services/Implementations/Database.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/Services/Implementations/Database.cs b/server/Services/Implementations/Database.cs index 76aa93f..dbf1995 100644 --- a/server/Services/Implementations/Database.cs +++ b/server/Services/Implementations/Database.cs @@ -25,7 +25,13 @@ public class Database : Server.Services.Interfaces.IDatabase { public DbRecord DbData { get; private set; } = new(3); - public IReadOnlyList Stations => stationListingsCollection.FindSync(_ => true).ToList(); + public IReadOnlyList Stations => stationListingsCollection + .Aggregate(PipelineDefinition.Create( + "{ $addFields: { stoppedAtCount: { $size: \"$stoppedAtBy\" } } }", + "{ $sort: { stoppedAtCount: -1 } }", + "{ $unset: \"stoppedAtCount\" }" + )) + .ToList(); public IReadOnlyList Trains => trainListingsCollection.FindSync(_ => true).ToList(); private static readonly string DbDir = Environment.GetEnvironmentVariable("DB_DIR") ?? Path.Join(Environment.CurrentDirectory, "db");