Reference

Operators, by profile

Every operator the grammar defines. The descriptions, operand shapes and examples on this page are read out of the schema when the site is built, so this is the grammar describing itself rather than a retelling that can drift.

What a profile is for

A profile is the unit a server advertises. core is required of every implementation; the rest are optional, and a server states which it serves. Accepting part of a profile is permitted — advertising it in that case is not. An operator outside the advertised set earns an unsupported-operator, not a silent wrong answer.

Reading the operand column

filter operators take whole filters and can appear at any level. field operators live inside a field's constraint object. operand forms appear where a value would go. Sibling operators on one field are combined with implicit AND, so {"age": {"$gt": 18, "$lt": 30}} is a single range.

core#

Required of every implementation. Logical composition, equality, ordering, sets, presence, and the resolver that turns UNKNOWN into a decision.

OperatorOperandMeaning
$andfilter an array of filters

All of the listed filters must evaluate TRUE.

$orfilter an array of filters

At least one of the listed filters must evaluate TRUE.

$norfilter an array of filters

NOT (a OR b OR …), evaluated under three-valued logic. It is TRUE only when every listed filter is FALSE: if one of them is UNKNOWN the result is UNKNOWN, not TRUE, so a $nor over a nullable field excludes the records whose field is null or absent. See the spec §4.1.

$notfilterfield a filter or a constraint

Negates a filter. Under three-valued logic NOT UNKNOWN is UNKNOWN, not TRUE — so this does not match records whose field is null or absent. Add $unknownAs to the inner constraint to include them. See the spec §4.1.

Negates the constraint on this field. {"age": {"$not": {"$gt": 5}}} is TRUE when age is not greater than 5 and UNKNOWN when age is null or absent.

$eqfield any JSON value

Field equals the operand. Any JSON value, including null, arrays and objects. A value of a different JSON type is unequal — FALSE, not UNKNOWN.

$nefield any JSON value

Field does not equal the operand. The negation of $eq under three-valued logic, so this is UNKNOWN — and therefore does not match — when the field is null or absent. Add $unknownAs: true to include those records. See the spec §4.1.

$infield a set of operands

Field equals at least one member of the list. Compares the whole value — it does NOT test membership inside an array-valued field: {"tags": {"$in": ["a"]}} asks whether tags equals "a". For array elements quantify explicitly: {"tags": {"$some": {"$in": ["a"]}}}.

$ninfield a set of operands

Field equals no member of the list. Like $in, compares the whole value rather than array elements. The negation of $in under three-valued logic, so it is UNKNOWN when the field is null or absent.

$gtfield an ordered value

Field is strictly greater than the operand.

$gtefield an ordered value

Field is greater than or equal to the operand.

$ltfield an ordered value

Field is strictly less than the operand.

$ltefield an ordered value

Field is less than or equal to the operand.

$existsfield a boolean

true if the field is present on the record, even when its value is null; false if absent. Total — never UNKNOWN. Distinct from $isNull — see the spec §4.2.

$isNullfield a boolean

true if the field's value is null (equivalent to {"$eq": null}); false if it is non-null (equivalent to {"$ne": null}). UNKNOWN only when the path resolves to nothing.

$unknownAsfield a boolean

Resolves UNKNOWN to TRUE or FALSE for this constraint, applied last — after every sibling operator, including a field-level $not. {"status": {"$ne": "archived", "$unknownAs": true}} means not archived, and count the records where status is null or absent. A modifier, not a predicate: it needs at least one operator beside it. No-op on $exists, which is already total. See the spec §4.6.

strings#

SQL LIKE patterns and literal substring tests.

OperatorOperandMeaning
$likefield a string

SQL LIKE pattern: % matches any run of characters, _ matches exactly one, and \ escapes either. Case-sensitive.

$nlikefield a string

Negated $like, under three-valued logic: UNKNOWN when the field is null, absent or not a string.

$ilikefield a string

Case-insensitive $like. Collation is server-defined; see the spec §5.5.

$nilikefield a string

Negated $ilike, under three-valued logic: UNKNOWN when the field is null, absent or not a string.

$startsWithfield a string

Field begins with this literal substring. Wildcards are not interpreted.

$endsWithfield a string

Field ends with this literal substring. Wildcards are not interpreted.

$containsfield a string

Field contains this literal substring. String-only — for arrays, quantify over the elements with $some or $every.

regex#

ECMA-262 regular expressions. Kept apart from strings because a regex engine is a real cost, and a bounded one is a real risk.

OperatorOperandMeaning
$regexfield a string

Field matches this regular expression (ECMA-262 syntax). Servers SHOULD bound execution time; see the spec §7.

$flagsfield a string matching ^[ims]{0,3}$

Modifiers for $regex: i case-insensitive, m multiline, s dot-matches-newline. Only valid alongside $regex.

ranges#

Inclusive two-sided bounds — one clause instead of two.

OperatorOperandMeaning
$betweenfield [lower, upper]

Field falls within [lower, upper], inclusive of both bounds.

$nbetweenfield [lower, upper]

Field falls outside [lower, upper]. The negation of $between under three-valued logic, so it is UNKNOWN when the field is null or absent.

types#

The field's JSON type, for records whose shape is not fixed.

OperatorOperandMeaning
$typefield "string" · "number" · "integer" · "boolean" · "object" · "array" · "null"

Fields JSON type. integer' matches a number with no fractional part.

collections#

Quantification over the elements of an array-valued field, and its length.

OperatorOperandMeaning
$somefield a filter or a constraint

At least one element of the array-valued field satisfies this condition. Supply a Filter for arrays of objects (paths are relative to the element) or a constraint object for arrays of scalars. An element for which the condition is UNKNOWN does not satisfy it, so the quantifier yields TRUE or FALSE over any array — FALSE for an empty one. It is UNKNOWN only when the field is not an array, including when it is null or absent. See the spec §5.8.

$everyfield a filter or a constraint

Every element of the array-valued field satisfies this condition; an element for which it is UNKNOWN does not. TRUE for an empty array, vacuously. UNKNOWN only when the field is not an array, including when it is null or absent — a missing array is not vacuously TRUE. Same operand shape as $some. See the spec §5.8.

$hasAllfield a set of operands

The array-valued field contains every member of this list. Quantifies over the operand rather than over the elements, which is why it is not expressible as a $some or $every. Set semantics: multiplicity is ignored. UNKNOWN when the field is not an array.

$sizefield a length, or a constraint on it

Length of the array-valued field: either an exact count or a nested numeric constraint.

refs#

Comparing one field against another, and escaping data that would otherwise be read as an operator.

OperatorOperandMeaning
$fieldoperand FieldPath

Compares against another field of the same record rather than a constant: {"price": {"$gt": {"$field": "cost"}}} is SQL's WHERE price > cost.

$literaloperand

Forces the wrapped value to be treated as data. Required only when an object operand would otherwise look like a field reference, e.g. {"$literal": {"$field": "not-a-reference"}}.

text#

Free-text match. Tokenisation, stemming and relevance are server-defined, so two conforming servers may rank differently.

OperatorOperandMeaning

Two things the table cannot show

Negations are three-valued. $ne, $nin, $nlike, $nbetween and $not do not match records where the field is null or absent, because the comparison is UNKNOWN rather than TRUE. Add $unknownAs to decide it explicitly.

$in is not array membership. It compares the whole field value against each member of the list. To say something about the elements of an array, quantify: {"tags": {"$some": {"$in": ["a"]}}}.

Full semantics for every operator: specification §5.