diff --git a/server/db/mongo/modules/checkModule.js b/server/db/mongo/modules/checkModule.js index f409fd3d2..a53384d1a 100755 --- a/server/db/mongo/modules/checkModule.js +++ b/server/db/mongo/modules/checkModule.js @@ -73,7 +73,7 @@ const getChecksByMonitor = async ({ rowsPerPage = parseInt(rowsPerPage); // Match const matchStage = { - monitorId: ObjectId.createFromHexString(monitorId), + monitorId: new ObjectId(monitorId), ...(typeof status !== "undefined" && { status }), ...(dateRangeLookup[dateRange] && { createdAt: { @@ -161,7 +161,7 @@ const getChecksByTeam = async ({ page = parseInt(page); rowsPerPage = parseInt(rowsPerPage); const matchStage = { - teamId: ObjectId.createFromHexString(teamId), + teamId: new ObjectId(teamId), status: false, ...(dateRangeLookup[dateRange] && { createdAt: { diff --git a/server/db/mongo/modules/diagnosticModule.js b/server/db/mongo/modules/diagnosticModule.js index 7a51ad193..e59830518 100755 --- a/server/db/mongo/modules/diagnosticModule.js +++ b/server/db/mongo/modules/diagnosticModule.js @@ -19,7 +19,7 @@ const getMonitorsByTeamIdExecutionStats = async (req) => { order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const matchStage = { teamId: new ObjectId(req.params.teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } diff --git a/server/db/mongo/modules/monitorModule.js b/server/db/mongo/modules/monitorModule.js index 32ed8b146..bc31915c2 100755 --- a/server/db/mongo/modules/monitorModule.js +++ b/server/db/mongo/modules/monitorModule.js @@ -523,7 +523,7 @@ const getMonitorsByTeamId = async ({ order = "asc"; } // Build match stage - const matchStage = { teamId: ObjectId.createFromHexString(teamId) }; + const matchStage = { teamId: new ObjectId(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -563,8 +563,7 @@ const getMonitorsByTeamId = async ({ const getMonitorsAndSummaryByTeamId = async ({ type, explain, teamId }) => { try { - const parsedTeamId = ObjectId.createFromHexString(teamId); - const matchStage = { teamId: parsedTeamId }; + const matchStage = { teamId: new ObjectId(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } @@ -606,9 +605,8 @@ const getMonitorsWithChecksByTeamId = async ({ field = "name"; order = "asc"; } - const parsedTeamId = ObjectId.createFromHexString(teamId); // Build match stage - const matchStage = { teamId: parsedTeamId }; + const matchStage = { teamId: new ObjectId(teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } diff --git a/server/db/mongo/modules/monitorModuleQueries.js b/server/db/mongo/modules/monitorModuleQueries.js index 35ddb8478..ab45eebb6 100755 --- a/server/db/mongo/modules/monitorModuleQueries.js +++ b/server/db/mongo/modules/monitorModuleQueries.js @@ -4,7 +4,7 @@ const buildUptimeDetailsPipeline = (monitorId, dates, dateString) => { return [ { $match: { - monitorId: ObjectId.createFromHexString(monitorId), + monitorId: new ObjectId(monitorId), createdAt: { $gte: dates.start, $lte: dates.end }, }, }, @@ -407,6 +407,16 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { ], }, }, + { $unwind: "$checks" }, + { $sort: { "checks._id": 1 } }, + { + $group: { + _id: "$_id", + checks: { $push: "$checks" }, + aggregateData: { $first: "$aggregateData" }, + upChecks: { $first: "$upChecks" }, + }, + }, { $project: { aggregateData: { @@ -415,12 +425,7 @@ const buildHardwareDetailsPipeline = (monitor, dates, dateString) => { upChecks: { $arrayElemAt: ["$upChecks", 0], }, - checks: { - $sortArray: { - input: "$checks", - sortBy: { _id: 1 }, - }, - }, + checks: 1, }, }, ]; @@ -734,7 +739,7 @@ const buildGetMonitorsByTeamIdPipeline = (req) => { order = "asc"; } // Build the match stage - const matchStage = { teamId: ObjectId.createFromHexString(req.params.teamId) }; + const matchStage = { teamId: new ObjectId(req.params.teamId) }; if (type !== undefined) { matchStage.type = Array.isArray(type) ? { $in: type } : type; } diff --git a/server/db/mongo/modules/statusPageModule.js b/server/db/mongo/modules/statusPageModule.js index e94ffbd55..f0f2fa762 100755 --- a/server/db/mongo/modules/statusPageModule.js +++ b/server/db/mongo/modules/statusPageModule.js @@ -134,6 +134,9 @@ const getStatusPage = async (url) => { }, }, }, + { $match: { "monitors.orderIndex": { $ne: -1 } } }, + { $sort: { "monitors.orderIndex": 1 } }, + { $group: { _id: "$_id", @@ -156,20 +159,7 @@ const getStatusPage = async (url) => { showAdminLoginLink: 1, url: 1, }, - monitors: { - $filter: { - input: { - $sortArray: { - input: "$monitors", - sortBy: { orderIndex: 1 }, - }, - }, - as: "monitor", - cond: { - $ne: ["$$monitor.orderIndex", -1], - }, - }, - }, + monitors: 1, }, }, ]);