AzureTipsAndTricks/blog/tip67.md

1.1 KiB

type title excerpt tags date
post Tip 67 - Querying documents properties with special characters in Cosmos DB Learn how to query documents properties with special characters in Cosmos DB
Databases
2017-12-12 17:00:00

::: tip 💡 Learn more : Azure Cosmos DB. :::

Querying documents properties with special characters in Cosmos DB

I was working with Cosmos DB yesterday and hit the following snag that I couldn't query my document that had special characters in it. Such is an example:

Notice the "$type": "mytype", has a $ in it.

If you head over to Query Explorer and try to query it using...

SELECT *
FROM testing t
WHERE t.$type = 'mytype'

... then you'll see the following error:

I was able to fix this by wrapping the property inside [] such as...

SELECT *
FROM testing t
WHERE t["$type"] = 'mytype'

Now my query returned properly