18 Querying MongoDB Atlas using SQL

 

This chapter covers

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

MongoDB Atlas enables SQL querying through its 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 tools like Power BI and Tableau.

The MongoDB 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, a SQL-92 compatible dialect, they are designed to eliminate the need for complex ETL, enabling faster insights on Atlas data while preserving the richness of the document model.

18.1 Introducing MongoDB Atlas SQL interface

18.1.1 Defining collections schema

18.2 Connecting to the Atlas SQL Interface

18.2.1 Enabling the Atlas SQL Interface

18.2.2 Accessing Atlas SQL 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 Using UNWIND and FLATTEN with Atlas SQL

18.4 Summary