Compatibility
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
| Operator | Description |
|---|---|
$eq | Matches values equal to a specified value |
$gt | Matches values greater than a specified value |
$gte | Matches values greater than or equal to a specified value |
$in | Matches any of the values in an array |
$lt | Matches values less than a specified value |
$lte | Matches values less than or equal to a specified value |
$ne | Matches values not equal to a specified value |
$nin | Matches none of the values in an array |
Logical
| Operator | Description |
|---|---|
$and | Joins query clauses with a logical AND |
$or | Joins query clauses with a logical OR |
$nor | Joins query clauses with a logical NOR |
$not | Inverts the effect of a query expression |
Element
| Operator | Description |
|---|---|
$exists | Matches documents that have the specified field |
$type | Matches documents where the field is a specified BSON type |
Evaluation
| Operator | Description |
|---|---|
$expr | Allows use of aggregation expressions within the query language, refer to the expressions section for supported expressions |
$mod | Performs a modulo operation on the value of a field |
$regex | Matches values against a regular expression |
$text | Performs 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
| Operator | Description |
|---|---|
$all | Matches arrays that contain all specified elements |
$elemMatch | Matches documents where an array field element satisfies all specified conditions |
$size | Matches arrays with a specific number of elements |
Bitwise
| Operator | Description |
|---|---|
$bitsAllClear | Matches where all bit positions are clear |
$bitsAllSet | Matches where all bit positions are set |
$bitsAnyClear | Matches where any bit position is clear |
$bitsAnySet | Matches where any bit position is set |
Geospatial
| Operator | Description |
|---|---|
$geoIntersects | Selects geometries that intersect with a GeoJSON geometry |
$geoWithin | Selects geometries within a bounding geometry ($geometry, $box, $polygon, $center, $centerSphere) |
$near | Returns documents sorted by proximity to a point |
$nearSphere | Returns documents sorted by proximity on a sphere |
$minDistance | Minimum distance filter for $near / $nearSphere |
$maxDistance | Maximum distance filter for $near / $nearSphere |
Not supported
| Operator | Reason |
|---|---|
$where | Blocked for security — allows arbitrary JavaScript execution |
$jsonSchema | Not yet implemented |
$rand | Not yet implemented |
$comment | Not yet implemented |
Update operators
| Operator | Description |
|---|---|
$set | Sets the value of a field |
$unset | Removes a field |
$inc | Increments a numeric field by a specified amount |
$ operators are supported in update operator keys.Aggregation
Pipeline stages
| Stage | Description |
|---|---|
$match | Filters documents (uses the same filter operators listed above) |
$project | Reshapes documents by including, excluding, or computing fields |
$sort | Sorts documents by specified fields (1 ascending, -1 descending, { $meta: "textScore" }) |
$skip | Skips a specified number of documents |
$limit | Limits the number of documents |
$unwind | Deconstructs an array field into separate documents |
$group | Groups documents by an expression and applies accumulators |
$search | Atlas Search integration (see below) |
Expressions
Expressions are used inside $group, $project, and $expr. Currently supported:
| Expression | Description |
|---|---|
$avg | Returns the average of values (single or array) |
$max | Returns the maximum value (single or array) |
$min | Returns the minimum value (single or array) |
$sum | Returns the sum of values (array) |
$median | Returns the approximate median (method: "approximate") |
$first | Returns the first value |
$firstN | Returns the first N values |
$last | Returns the last value |
$lastN | Returns the last N values |
$in | Returns whether a value is in an array |
Group accumulators
The $group stage supports the following accumulators:
| Accumulator | Description |
|---|---|
$avg | Average of values |
$count | Count of documents |
$first / $firstN | First value(s) |
$last / $lastN | Last value(s) |
$max | Maximum value |
$median | Approximate median |
$min | Minimum value |
$sum | Sum of values |
Atlas Search ($search)
The $search stage supports the following operators:
| Operator | Description |
|---|---|
compound | Combines multiple operators with must, mustNot, should, and filter clauses |
text | Full-text search with optional fuzzy matching, matchCriteria, and synonyms |
autocomplete | Autocomplete 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.