Search code examples
azure-cosmosdbazure-cosmosdb-sqlapi

cosmos db select query array having space and special chars


I need to write a query that finds all data that have for e.g. 0.09 pulgadas

Data in Cosmos is as follows

{
    
    "itemId": "62909753",
    "doc": {
        "facets": {
            "tamaño de pantalla": [
                "0.09 pulgadas"
            ]
        }
    },
    "deleted": false,
    "ttl": -1,
    "id": "06e4c982e4f1",
    "_ts": 1678962661
}

I am getting syntax errors and I am unable to query due to following issues

  • tamaño de pantalla has spaces and also has special characters.

Solution

  • Here, Is the query that finds all data that have for e.g. 0.09 pulgadas:

    • SELECT * FROM c WHERE c.doc.facets["tamaño de pantalla"] = ["0.09 pulgadas"]

    • c.doc.facets["tamaño de pantalla"] This expression retrieves the value of the "tamaño de pantalla" field from the "facets" property of document in the container.

    • I have used [ ] because 0.09 pulgadas is present in an array so we should retrieve through an array. Hence, I gave "tamaño de pantalla" in an array.

    • Below is the item in COSMOS-DB :

    enter image description here

    • The result which I got is in the screenshot below:

    enter image description here