简体   繁体   English

DocumentDB:如何在数组内的数组上过滤文档?

[英]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: 当我使用以下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. 据我所知,Azure Cosmos DB尚不支持Distinct

It seems that there is no way to remove the repeat data in the query SQL level. 似乎无法删除查询SQL级别中的重复数据。

You could handle with your query result set in the loop locally. 您可以在本地loop处理查询结果集。

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. 但是,如果结果数据很大,建议您使用存储过程在Azure Cosmos DB中处理结果数据,以减轻本地服务器上的压力。

You could refer to the official tutorial about SP. 您可以参考有关SP的官方教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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