From c61f08b31c0ab553df61386f9a9f3c95b1eb3565 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 10 Jan 2025 20:06:01 -0800 Subject: [PATCH] Add a default sort order if a field to sort by is not specified --- Server/db/mongo/modules/monitorModule.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Server/db/mongo/modules/monitorModule.js b/Server/db/mongo/modules/monitorModule.js index df80855bd..4c60e0f22 100644 --- a/Server/db/mongo/modules/monitorModule.js +++ b/Server/db/mongo/modules/monitorModule.js @@ -501,7 +501,10 @@ const getMonitorsByTeamId = async (req) => { limit = parseInt(limit); page = parseInt(page); rowsPerPage = parseInt(rowsPerPage); - + if (field === undefined) { + field = "name"; + order = "asc"; + } // Build the match stage const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; if (type !== undefined) { @@ -511,7 +514,6 @@ const getMonitorsByTeamId = async (req) => { const skip = page && rowsPerPage ? page * rowsPerPage : 0; const sort = { [field]: order === "asc" ? 1 : -1 }; - const results = await Monitor.aggregate([ { $match: matchStage }, {