meteor/meteor · error · MiniMongoQueryError
Only the i, m, and g regexp options are supported
Error message
Only the i, m, and g regexp options are supported
What it means
Thrown by the $regex operator when the accompanying $options string contains any character other than i, m, or g. minimongo only supports the JavaScript RegExp flags; MongoDB-specific flags like x (extended) and s (dotAll) are not implemented and are explicitly rejected.
Source
Thrown at packages/minimongo/common.js:185
};
},
},
$regex: {
compileElementSelector(operand, valueSelector) {
if (!(typeof operand === 'string' || operand instanceof RegExp)) {
throw new MiniMongoQueryError('$regex has to be a string or RegExp');
}
let regexp;
if (valueSelector.$options !== undefined) {
// Options passed in $options (even the empty string) always overrides
// options in the RegExp object itself.
// Be clear that we only support the JS-supported options, not extended
// ones (eg, Mongo supports x and s). Ideally we would implement x and s
// by transforming the regexp, but not today...
if (/[^gim]/.test(valueSelector.$options)) {
throw new MiniMongoQueryError('Only the i, m, and g regexp options are supported');
}
const source = operand instanceof RegExp ? operand.source : operand;
regexp = new RegExp(source, valueSelector.$options);
} else if (operand instanceof RegExp) {
regexp = operand;
} else {
regexp = new RegExp(operand);
}
return regexpElementMatcher(regexp);
},
},
$elemMatch: {
dontExpandLeafArrays: true,
compileElementSelector(operand, valueSelector, matcher) {
if (!LocalCollection._isPlainObject(operand)) {
throw new MiniMongoQueryError('$elemMatch need an object');View on GitHub (pinned to 5076d2f818)
Solutions
- Use only i, m, and/or g: {field: {$regex: 'a.b', $options: 'im'}}.
- Drop the unsupported flag, or pre-process the regex to simulate x (strip whitespace/comments) or s (transform . ) client-side.
- If you need dotAll, rewrite the pattern to use [\s\S] instead of relying on the s flag.
Example fix
// before
collection.find({ body: { $regex: 'a.b', $options: 'is' } });
// after
collection.find({ body: { $regex: 'a[\s\S]b', $options: 'i' } }); Defensive patterns
Strategy: validation
Validate before calling
function regexWithOptions(pattern, options) {
if (options && /[^gim]/.test(options)) {
throw new Error('Only i, m, g flags are supported by minimongo');
}
return { $regex: pattern, $options: options || '' };
} Type guard
function areValidRegexFlags(flags) {
return typeof flags === 'string' && /^[gim]*$/.test(flags);
} Prevention
- Restrict $options to i, m, and g.
- Rewrite patterns needing s flag to use [\\s\\S].
- Strip x-flag and pre-remove whitespace/comments manually if needed.
When it happens
Trigger: Using {field: {$regex: 'a.b', $options: 'is'}} or {field: {$regex: 'a.b', $options: 'x'}} in a minimongo query. The check /[^gim]/.test(valueSelector.$options) catches any unsupported flag.
Common situations: Copying a query from MongoDB shell that uses x or s flags; combining flags and including an unsupported one; passing options as a multi-char string with a typo.
Related errors
- $options needs a $regex
- $regex has to be a string or RegExp
- 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/4cac54e6a32ca028.
Report an issue: GitHub.