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");