Advanced

Compatibility

Compatibility considerations and limitations when using Mongalayer compared to the MongoDB driver.

Mongalayer validates all incoming payloads against a strict schema. Only the operators and stages listed below are supported. Anything not listed will be rejected at runtime.

When using TypeScript, the type system will help ensure you only use supported operators and stages. The goal of this project is to provide the most common and useful MongoDB features while maintaining a secure and performant access layer.

Filter operators

Comparison

OperatorDescription
$eqMatches values equal to a specified value
$gtMatches values greater than a specified value
$gteMatches values greater than or equal to a specified value
$inMatches any of the values in an array
$ltMatches values less than a specified value
$lteMatches values less than or equal to a specified value
$neMatches values not equal to a specified value
$ninMatches none of the values in an array

Logical

OperatorDescription
$andJoins query clauses with a logical AND
$orJoins query clauses with a logical OR
$norJoins query clauses with a logical NOR
$notInverts the effect of a query expression

Element

OperatorDescription
$existsMatches documents that have the specified field
$typeMatches documents where the field is a specified BSON type

Evaluation

OperatorDescription
$exprAllows use of aggregation expressions within the query language, refer to the expressions section for supported expressions
$modPerforms a modulo operation on the value of a field
$regexMatches values against a regular expression
$textPerforms text search
$regex only supports string patterns. RegExp instances are not supported. The $options flag can be used alongside $regex with the characters i, m, s, x, and u.

Array

OperatorDescription
$allMatches arrays that contain all specified elements
$elemMatchMatches documents where an array field element satisfies all specified conditions
$sizeMatches arrays with a specific number of elements

Bitwise

OperatorDescription
$bitsAllClearMatches where all bit positions are clear
$bitsAllSetMatches where all bit positions are set
$bitsAnyClearMatches where any bit position is clear
$bitsAnySetMatches where any bit position is set

Geospatial

OperatorDescription
$geoIntersectsSelects geometries that intersect with a GeoJSON geometry
$geoWithinSelects geometries within a bounding geometry ($geometry, $box, $polygon, $center, $centerSphere)
$nearReturns documents sorted by proximity to a point
$nearSphereReturns documents sorted by proximity on a sphere
$minDistanceMinimum distance filter for $near / $nearSphere
$maxDistanceMaximum distance filter for $near / $nearSphere

Not supported

OperatorReason
$whereBlocked for security — allows arbitrary JavaScript execution
$jsonSchemaNot yet implemented
$randNot yet implemented
$commentNot yet implemented

Update operators

OperatorDescription
$setSets the value of a field
$unsetRemoves a field
$incIncrements a numeric field by a specified amount
Dot notation and positional $ operators are supported in update operator keys.

Aggregation

Pipeline stages

StageDescription
$matchFilters documents (uses the same filter operators listed above)
$projectReshapes documents by including, excluding, or computing fields
$sortSorts documents by specified fields (1 ascending, -1 descending, { $meta: "textScore" })
$skipSkips a specified number of documents
$limitLimits the number of documents
$unwindDeconstructs an array field into separate documents
$groupGroups documents by an expression and applies accumulators
$searchAtlas Search integration (see below)

Expressions

Expressions are used inside $group, $project, and $expr. Currently supported:

ExpressionDescription
$avgReturns the average of values (single or array)
$maxReturns the maximum value (single or array)
$minReturns the minimum value (single or array)
$sumReturns the sum of values (array)
$medianReturns the approximate median (method: "approximate")
$firstReturns the first value
$firstNReturns the first N values
$lastReturns the last value
$lastNReturns the last N values
$inReturns whether a value is in an array

Group accumulators

The $group stage supports the following accumulators:

AccumulatorDescription
$avgAverage of values
$countCount of documents
$first / $firstNFirst value(s)
$last / $lastNLast value(s)
$maxMaximum value
$medianApproximate median
$minMinimum value
$sumSum of values

The $search stage supports the following operators:

OperatorDescription
compoundCombines multiple operators with must, mustNot, should, and filter clauses
textFull-text search with optional fuzzy matching, matchCriteria, and synonyms
autocompleteAutocomplete search with optional fuzzy matching and tokenOrder

All search operators support a score option with boost or constant modifiers.

Access filter operators

Access filters support a subset of operators plus custom Mongalayer operators for expression-based matching. Please refer to the access control documentation for details.

Supported value types

Mongalayer supports the following value types in documents and filters:

string, number, boolean, null, Date, nested objects, and arrays.

RegExp instances, Binary, and undefined are not supported as values. Dates are serialized and deserialized automatically through the client SDK.
Copyright © 2026