Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

$sql Stage (Atlas Data Federation)

$sql processes an SQL query of the data in a collection. The $sql stage:

  • Must be the first stage in the pipeline.

  • Supports SELECT and UNION statements only.

Use this stage for read-only queries.

{
$sql: {
statement: "<SQL-statement>",
excludeNamespaces: true | false
}
}
Field
Type
Description
Necessity

statement

string

SQL query or command to run.

Required

excludeNamespaces

boolean

Flag that specifies whether to exclude the namespaces in the result set.

Optional

The following example shows the $sql syntax for querying a sampleDB.egData collection:

{
$sql: {
statement: "select * from egData limit 2",
excludeNamespaces: true
}
}