carens
carens

Reputation: 319

DocumentDB: How to filter document on array within array?

Let's say I have the following document:

{
"Id": "1",
"Properties": [
    {
        "Name": "Name1",
        "PropertyTypes": [
            "Type1"
        ]
    },
    {
        "Name": "Name2",
        "PropertyTypes": [
            "Type1",
            "Type2",
            "Type3"
        ]
    }
]
}

When I use the following SQL:

SELECT c.Id FROM c
JOIN p in c.Properties
WHERE ARRAY_CONTAINS(p.PropertyTypes,"Type1")

I get as return:

[
{
    "Id": "1"
},
{
    "Id": "1"
}
]

How do I change my query so that it only returns distinct documents?

Upvotes: 0

Views: 258

Answers (1)

Jay Gong
Jay Gong

Reputation: 23782

As far as I know, Distinct hasn't supported by Azure Cosmos DB yet.

It seems that there is no way to remove the repeat data in the query SQL level.

You could handle with your query result set in the loop locally.

However, if your result data is large,I suggest you using a stored procedure to handle with result data in Azure Cosmos DB to release the pressure on your local server.

You could refer to the official tutorial about SP.

Upvotes: 1

Related Questions