move filtering to the monitors facet

This commit is contained in:
Alex Holliday
2025-01-08 14:17:29 -08:00
parent 62541f3fdd
commit 40fbe4a822
2 changed files with 14 additions and 9 deletions
+12 -7
View File
@@ -523,13 +523,6 @@ const getMonitorsByTeamId = async (req) => {
const sort = { [field]: order === "asc" ? 1 : -1 };
if (filter !== undefined) {
matchStage.$or = [
{ name: { $regex: filter, $options: "i" } },
{ url: { $regex: filter, $options: "i" } },
];
}
const results = await Monitor.aggregate([
{ $match: matchStage },
{
@@ -563,6 +556,18 @@ const getMonitorsByTeamId = async (req) => {
},
],
monitors: [
...(filter !== undefined
? [
{
$match: {
$or: [
{ name: { $regex: filter, $options: "i" } },
{ url: { $regex: filter, $options: "i" } },
],
},
},
]
: []),
{ $sort: sort },
{ $skip: skip },
...(rowsPerPage ? [{ $limit: rowsPerPage }] : []),