18 Querying Atlas using SQL

 

This chapter covers

  • Exploring the Atlas SQL interface architecture
  • Enabling Atlas SQL interface with Quick Start
  • Connecting to the Atlas SQL interface with mongosh
  • Querying with the $sql aggregation pipeline stage
  • Operating a short-form SQL syntax with db.sql()

Atlas enables SQL querying through its Atlas Data Federation feature, allowing you to run SQL queries such as SELECT and WHERE statements directly on your MongoDB collections. This feature provides a unified interface for data analysis and reporting using familiar SQL syntax. This functionality also enables you to create visualizations, graphs, and reports on your Atlas data using relational business-intelligence (BI) tools such as Power BI and Tableau.

The Atlas SQL interface, along with its connectors and drivers, allows you to use your existing SQL skills to query and analyze live application data directly from your favorite SQL-based tools. Built with mongosql, an SQL-92–compatible dialect, this interface is designed to eliminate complex extract, transform, load (ETL) operations, enabling faster insights on Atlas data while preserving the richness of the document model.

18.1 Introducing the Atlas SQL interface

18.2 Connecting to the Atlas SQL interface

18.2.1 Enabling the interface

18.2.2 Accessing the interface

18.3 Querying MongoDB using SQL

18.3.1 Aggregation pipeline Atlas SQL syntax

18.3.2 Short-form Atlas SQL syntax

18.3.3 UNWIND and FLATTEN with Atlas SQL

Summary