SELECT statement where filtering, projection, grouping, sorting, and limiting are all expressed at once. There are no stages to compose β the query optimizer decides execution order.
This means most MongoDB aggregations collapse to a single DQL SELECT. Operations with no DQL equivalent β joins, window functions, set algebra, advanced math, and several array accumulators β are noted as gaps throughout and collected in the Known Gaps section.
AI Agent Prompt
Use this prompt with any AI coding assistant to convert a MongoDB aggregation pipeline to DQL.Copy AI Agent Prompt (Click to Expand)
Copy AI Agent Prompt (Click to Expand)
Quick Reference
The table below covers the most common MongoDB aggregation pipeline stages and expression operators. Where a direct equivalent exists, a DQL example is provided. Where one doesnβt exist yet, the notes column says so β if any of those are important to your use case, reach out to support and let us know.Filtering
$match β WHERE
MongoDB
DQL
=, !=, <, >, <=, >=, BETWEEN, IN, NOT IN, LIKE, ILIKE, SIMILAR TO, IS NULL, IS NOT NULL, IS MISSING, IS NOT MISSING.
DQL
Projection
$project (include fields)
MongoDB
DQL
$project (computed fields)
MongoDB
DQL
$addFields / $set β add fields while keeping all existing ones
MongoDB
DQL
SELECT *, price * 1.1 AS adjusted_price FROM products is a syntax error. The wildcard must be qualified with the collection name: SELECT products.*, ....$project (exclude fields) / $unset
MongoDB
DQL
MISSING override the wildcard expansion β products.* includes the field, but the explicit MISSING projection wins and the key is absent from output.
For excluding a nested field within an object value, use object_unset:
DQL
Grouping and Aggregation
$group
MongoDB
DQL
COUNT, SUM, AVG, MIN, MAX, MEDIAN, MID.
HAVING β filter on aggregated results
MongoDB
DQL
$addToSet / COUNT(DISTINCT ...)
DQL supports COUNT(DISTINCT ...) for counting unique values but does not accumulate values into an array within a group:
DQL
Sorting, Limiting, and Pagination
$sort, $limit, $skip
MongoDB
DQL
Counting
$count
MongoDB
DQL
DQL
Array Operations
$unwind β array transform or search expression
MongoDBβs $unwind duplicates a document for each array element. DQL has no row-multiplying unwind. Instead:
- Transform array contents in-place with the
ARRAYexpression - Filter documents based on array contents with
ANY ... IN ... SATISFIES
MongoDB
DQL
DQL
$map β ARRAY transformation expression
MongoDB
DQL
$filter β ARRAY ... WHEN expression
MongoDB
DQL
$arrayElemAt β subscript operator
MongoDB
DQL
$size β array_length()
MongoDB
DQL
$in (array membership) β array_contains()
MongoDB
DQL
Object Operations
$mergeObjects β object_concat()
MongoDB
DQL
$objectToArray β object_content()
MongoDB
DQL
object_content() returns an array of single-key objects. Available in SDK v4.11+. See Object Operators for full configuration options.
$arrayToObject β OBJECT transformation expression
MongoDB
DQL
Conditional Expressions
$cond β CASE WHEN
MongoDB
DQL
DQL
$ifNull β ifnull() / coalesce()
MongoDB
DQL
coalesce(v1, v2, ...) is a synonym that returns the first non-null, non-missing value.
$switch β simple CASE
MongoDB
DQL
Bucketing
$bucket / $bucketAuto β CASE + GROUP BY
MongoDB
DQL
Date Functions
DQL
String Functions
DQL
Type Inspection and Casting
$type β type() / json_type()
MongoDB
DQL
type() returns DQL type names (boolean, string, integer, float, object, array, binary, null, missing). json_type() returns JSON type names (boolean, string, number, object, array, binary, null), returning "null" for MISSING values.
$toString, $toInt, $toDouble, etc. β cast()
MongoDB
DQL
'string', 'integer', 'float', 'boolean', 'binary'. Also accepts CAST(v AS type) SQL syntax. Returns MISSING if conversion is not possible.
Multi-Stage Pipelines β Single SELECT
A MongoDB pipeline composing multiple stages maps to a single DQLSELECT:
MongoDB
DQL
Transaction Workarounds
Dittoβstransaction() API runs multiple DQL statements in a single atomic block at serializable isolation β either all statements commit or none do. This covers several patterns that have no direct DQL equivalent. Examples below use JavaScript; the same pattern applies in all supported SDKs.
Simulating Joins
DQL has no join syntax, but a read-only transaction guarantees both queries see the same consistent snapshot of the store. Combine the results in application code:JavaScript
Consistent Multi-Query Snapshot
The equivalent of$facet β run independent aggregations that are guaranteed to reflect the same point in time:
JavaScript
Atomic Read-Modify-Write
The equivalent of$merge / $out β aggregate, transform in application code, then write the results back in the same atomic operation:
JavaScript
Known Gaps
The following MongoDB aggregation capabilities have no DQL equivalent.Pipeline Stages
Grouping and Accumulators
Array Operations
String Operations
Math Functions
DQL providesabs(), ceil(), and floor(). The following have no equivalent: