Azure Comos DB Portal SQL Cheat Sheet

By Stephen Garside on 12/1/2017

Microsoft Azure ComosDB SQL Query Cheat Sheet and Examples

I have recently had the opportunity to use Cosmos DB in Microsoft Azure for a project , so have started to pull together a cheat sheet for all the different things I find out on my travels - hope you find it useful!

 

SQL Query Where Cosmos DB Contains Or Like

SELECT * FROM c WHERE CONTAINS(c.id, "RK0305500")

 

SQL Query Where Cosmos DB Ends With a String

SELECT * FROM c WHERE ENDSWITH(c.id, "_somestring")

 

SQL Query Where Cosmos DB Field Name Contains a Space

SELECT * FROM c WHERE CONTAINS(c["Product Level"], "Level 1")

 

Total Document Count In Azure DB Collection

SELECT VALUE COUNT(1) FROM c

 

Select Multiple Nested Properties From Documents in CosmosDB

In the example below, 'parent' is the parent item, and 'ChildProducts' is an array of properties off each parent. These child arrays hold the 'Some Property Name' property.

SELECT child["Some Property Name"] FROM parent JOIN child IN parent.ChildProducts WHERE parent.id = "Some Id"