Microsoft Azure Cosmos DB supports querying documents using SQL (Structured Query Language) as a JSON query language. Cosmos DB is truly schema-free. By its commitment to the JSON data model directly within the database engine, it provides automatic indexing of JSON documents without requiring explicit schema or creation of secondary indexes.
Azure DocumentDB supports query JSON documents using familiar and friendly SQL syntax. If you know SQL, you can get up and running quickly with Azure DocumentDB. It also helps in quick writing the queries for DocumentDB API data by displaying common database queries, keywords, built-in functions, and operators in an easy to print PDF reference sheet.
This cheat sheet helps write DocumentDB queries quickly by showing some common SQL queries used to retrieve data from two simple JSON documents. For a relational database example, there are two key differences when writing queries on Azure DocumentDB.
- We can query without specifying explicit schema or creating secondary indexes. This is possible due to DocumentDB’s deep commitment to the JSON data model. Since JSON always contains metadata in the form of property names in addition to values, DocumentDB can determine the schema and index data as documents are inserted, and lets you query against that index.
The above SQL cheat sheet PDF shows common queries used to retrieve data from two example JSON documents. In case you are looking to run and test SQL, you can use Online Demo. You can also review SQL queries for Azure Cosmos DB DocumentDB API at MS Document.