简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM