Automattic/mongoose · error · Error
`$expr` must be an object or boolean literal
Error message
`$expr` must be an object or boolean literal
What it means
Error "`$expr` must be an object or boolean literal" thrown in Automattic/mongoose.
Source
Thrown at lib/helpers/query/cast$expr.js:76
'$week',
'$dayOfMonth',
'$dayOfYear',
'$hour',
'$minute',
'$second',
'$isoDayOfWeek',
'$isoWeekYear',
'$isoWeek',
'$millisecond'
]);
const expressionOperator = new Set(['$not']);
module.exports = function cast$expr(val, schema, strictQuery) {
if (typeof val === 'boolean') {
return val;
}
if (typeof val !== 'object' || val === null) {
throw new Error('`$expr` must be an object or boolean literal');
}
return _castExpression(val, schema, strictQuery);
};
function _castExpression(val, schema, strictQuery) {
// Preserve the value if it represents a path or if it's null
if (isPath(val) || val === null) {
return val;
}
if (val.$cond != null) {
if (Array.isArray(val.$cond)) {
val.$cond = val.$cond.map(expr => _castExpression(expr, schema, strictQuery));
} else {
val.$cond.if = _castExpression(val.$cond.if, schema, strictQuery);
val.$cond.then = _castExpression(val.$cond.then, schema, strictQuery);
val.$cond.else = _castExpression(val.$cond.else, schema, strictQuery);View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/helpers/query/cast$expr.js:76 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/9e302b688e400a88.
Report an issue: GitHub.