[NoBrainer] Filter items on nested properties in Azure Cosmos DB Data Explorer

In this post I quickly explain how to filter items of a Cosmos DB container based on nested properties by using Data Explorer of Azure Cosmos DB account in Azure portal.

Suppose there is a container named People and the following item structure.

{
    "person": {
        "firstName": "John",
        "lastName": "Doe",
        "personId": "1234",
        "addresses": [
            {
                "street": "Arbitrary street",
                "zipCode": "23456",
                "city": "Arbitrary city",
                "country": "Arbitrary country",
                "status": "Active"
            }
        ],
    },
    "id": "1234",
    "partitionKey": "people",
    "_rid": "...==",
    "_self": "...",
    "_etag": "...",
    "_attachments": "attachments/",
    "_ts": 1659705160
}

In Data Explorer of Azure Cosmos DB account, select the corresponding container and then select Items. Now the default filter can be extended by clicking on the Edit Filter button.

To filter for person items with lastName equals Doe, the query part to add looks as follows:

WHERE c["person"].lastName = "Doe"

To filter for person items with address(es) in status Active, the query part to add looks as follows:

WHERE ARRAY_CONTAINS(c["person"].addresses, {"status": "DeniedByAll"}, true)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: