Azure Comos DB Portal SQL Cheat Sheet

By SG Digital 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



SQL Query Where Cosmos DB Ends With a String

SELECT * FROM c WHERE ENDSWITH(, "_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 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 = "Some Id"


SELECT * FROM c WHERE ARRAY_CONTAINS(c.Intents, 'Question_StockGeneral',true)


Select Entire Parent Record Using Property on Child in CosmosDB

SELECT VALUE parent FROM parent JOIN child IN parent.ChildProducts WHERE "some id"


Select Distinct Value From Child Array Property in CosmosDB

SELECT distinct VALUE ChildArrayName from c join ChildArrayName in c.ChildArrayName where ...