Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cosmos DB: Querying documents properties with special characters such as "$"

I've got a Cosmos DB collection with a document that contains properties that have a special character and what I assume is a reserved word. An example document is:

{
   $type: 'Some value', 
   Value: 'Some other value'
}

If I execute the following query in the Azure Portal Query Explorer:

select * from c where c.Value = 'Some other value'

I receive an error of "Syntax error, incorrect syntax near 'Value'.". I get a similar error querying on c.$type.

How do I escape these property values so that I can query?

like image 373
Rob Reagan Avatar asked Nov 07 '17 19:11

Rob Reagan


Video Answer


1 Answers

In the case of special characters, you will need to wrap the property inside []

Example:

SELECT * FROM c WHERE c["$type"] = "Some value"

SELECT * FROM c WHERE c["value"] = "$Some other value"

like image 150
M0rty Avatar answered Nov 09 '22 22:11

M0rty