{"record":{"id":"16f8d95d4bdcdbf9","repo":"louislam/uptime-kuma","slug":"query-result-did-not-meet-the-specified-conditions-16f8d9","errorCode":null,"errorMessage":"Query result did not meet the specified conditions (${result})","messagePattern":"Query result did not meet the specified conditions \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/monitor-types/mysql.js","lineNumber":42,"sourceCode":"\n        // Use `radius_password` as `password` field for backwards compatibility\n        // TODO: rename `radius_password` to `password` later for general use\n        const password = monitor.radiusPassword;\n\n        const conditions = monitor.conditions ? ConditionExpressionGroup.fromMonitor(monitor) : null;\n        const hasConditions = conditions && conditions.children && conditions.children.length > 0;\n\n        const startTime = dayjs().valueOf();\n        try {\n            if (hasConditions) {\n                // When conditions are enabled, expect a single value result\n                const result = await this.mysqlQuerySingleValue(monitor.databaseConnectionString, query, password);\n                heartbeat.ping = dayjs().valueOf() - startTime;\n\n                const conditionsResult = evaluateExpressionGroup(conditions, { result: String(result) });\n\n                if (!conditionsResult) {\n                    throw new Error(`Query result did not meet the specified conditions (${result})`);\n                }\n\n                heartbeat.status = UP;\n                heartbeat.msg = \"Query did meet specified conditions\";\n            } else {\n                // Backwards compatible: just check connection and return row count\n                const result = await this.mysqlQuery(monitor.databaseConnectionString, query, password);\n                heartbeat.ping = dayjs().valueOf() - startTime;\n                heartbeat.status = UP;\n                heartbeat.msg = result;\n            }\n        } catch (error) {\n            heartbeat.ping = dayjs().valueOf() - startTime;\n            // Re-throw condition errors as-is, wrap database errors\n            if (error.message.includes(\"did not meet the specified conditions\")) {\n                throw error;\n            }\n            throw new Error(`Database connection/query failed: ${error.message}`);","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/louislam/uptime-kuma/blob/6b5ea0155793e666666745fb8d6fef1e829543a2/server/monitor-types/mysql.js#L24-L60","documentation":"Thrown by MysqlMonitorType.check when conditions are configured and the single-value result does not satisfy evaluateExpressionGroup({result: String(result)}). Identical semantics to the MSSQL variant: only the 'result' variable is exposed, and the value is stringified before comparison.","triggerScenarios":"monitor.conditions has children, mysqlQuerySingleValue returns a scalar, and evaluateExpressionGroup over {result: String(result)} is false. Mismatches arise from MySQL's type formatting (DECIMAL as '12.30', BIT as Buffer, TINYINT(1) as 0/1, JSON values).","commonSituations":"DECIMAL columns returning trailing zeros; BIT(1) returned as a Buffer that stringifies oddly; datetime formatted with locale; condition references wrong variable; condition literal doesn't match MySQL's string coercion.","solutions":["Run the exact query in the mysql CLI from the monitor host and inspect the value's string form.","Condition must reference 'result'; use numeric operators for numeric columns.","Cast in SQL (CAST(col AS CHAR), CAST(col AS SIGNED), ROUND(col,n)) so the stringified value matches the condition literal.","Validate with a BETWEEN/range condition instead of strict equality for floats."],"exampleFix":"-- before: SELECT AVG(price) FROM orders;   -> '12.3400'\n-- after:  SELECT ROUND(AVG(price),2) FROM orders;  -> '12.34'\n-- condition: result >= 12 and result <= 13","handlingStrategy":"try-catch","validationCode":"const scalar = await mysqlMonitor.mysqlQuerySingleValue(connStr, query, password);\nconst ok = evaluateExpressionGroup(group, { result: String(scalar) });","typeGuard":"function conditionUsesResultVar(group) { return group.children.every(c => c.variable === 'result'); }","tryCatchPattern":"try { await mysqlMonitor.check(monitor, heartbeat, server); }\ncatch (e) { if (/did not meet the specified conditions/.test(e.message)) { heartbeat.status = DOWN; heartbeat.msg = e.message; } else throw e; }","preventionTips":["Cast/round in SQL (CAST(... AS CHAR), ROUND) so the stringified value is deterministic.","Reference only 'result'; use numeric operators for numeric columns.","Beware DECIMAL trailing zeros and BIT/TINYINT(1) coercion in MySQL."],"tags":["mysql","mariadb","conditions","database","uptime-kuma"],"backgroundTag":null,"analyzedSha":"6b5ea0155793e666666745fb8d6fef1e829543a2","analyzedAt":"2026-08-12T23:42:12.959Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}