meteor/meteor · error · MiniMongoQueryError
argument to $type is not a number or a string
Error message
argument to $type is not a number or a string
What it means
Thrown by the $type operator when the operand is neither a string (alias) nor a number (BSON code). $type only accepts those two operand kinds; anything else (boolean, array, object, null, undefined) is rejected before any alias/code lookup.
Source
Thrown at packages/minimongo/common.js:126
'javascriptWithScope': 15,
'int': 16,
'timestamp': 17,
'long': 18,
'decimal': 19,
'minKey': -1,
'maxKey': 127,
};
if (!hasOwn.call(operandAliasMap, operand)) {
throw new MiniMongoQueryError(`unknown string alias for $type: ${operand}`);
}
operand = operandAliasMap[operand];
} else if (typeof operand === 'number') {
if (operand === 0 || operand < -1
|| (operand > 19 && operand !== 127)) {
throw new MiniMongoQueryError(`Invalid numerical $type code: ${operand}`);
}
} else {
throw new MiniMongoQueryError('argument to $type is not a number or a string');
}
return value => (
value !== undefined && LocalCollection._f._type(value) === operand
);
},
},
$bitsAllSet: {
compileElementSelector(operand) {
const mask = getOperandBitmask(operand, '$bitsAllSet');
return value => {
const bitmask = getValueBitmask(value, mask.length);
return bitmask && mask.every((byte, i) => (bitmask[i] & byte) === byte);
};
},
},
$bitsAnySet: {
compileElementSelector(operand) {View on GitHub (pinned to 5076d2f818)
Solutions
- Provide a string alias or numeric code: {field: {$type: 'string'}}.
- If the operand is optional, default it before building the selector.
- Validate the operand is string|number before constructing the query.
Example fix
// before
collection.find({ value: { $type: true } });
// after
collection.find({ value: { $type: 'bool' } }); Defensive patterns
Strategy: type-guard
Validate before calling
function typeSelector(operand) {
if (typeof operand !== 'string' && typeof operand !== 'number') {
throw new TypeError('$type operand must be string alias or number code');
}
return { $type: operand };
} Type guard
function isValidTypeOperand(op) {
return typeof op === 'string' || typeof op === 'number';
} Prevention
- Only pass string aliases or numeric codes to $type.
- Default optional operands before building the selector.
- Validate operand type at the selector-builder boundary.
When it happens
Trigger: Using {field: {$type: true}}, {field: {$type: null}}, {field: {$type: [1]}}, or {field: {$type: {}}} in a minimongo query.
Common situations: Passing a boolean flag; passing null from an optional config; wrapping the code in an array; passing an object that was meant for a different operator.
Related errors
- unknown string alias for $type: ${operand}
- Invalid numerical $type code: ${operand}
- argument to $mod must be an array of two numbers
- $in needs an array
- cannot nest $ under $in
AI-assisted analysis of meteor/meteor@5076d2f818 (2026-08-13).
Data as JSON: /api/errors/80e502459206f5f8.
Report an issue: GitHub.