DocumentDB使用数组查询 [英] DocumentDB queries with arrays

查看:110
本文介绍了DocumentDB使用数组查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的(与字符串)数组属性的文件。

I have documents with a simple (string-)array property.

{
     "id": "one",
     "tags": ["A", "B"]
}

{
     "id": "two",
     "tags": ["A", "C"]
}

要检查,如果值是阵列的一部分,我可以使用ARRAY_CONTAINS

To check, if a value is part of an array, I could use ARRAY_CONTAINS

SELECT * FROM c WHERE ARRAY_CONTAINS(c.tags, "B")

会返回文档一。

我怎么可以查询文件可能值的数组列表?

How could I query for documents with a list of possible values in the array?

返回所有在那里的标签阵列中的至少一个值列在文件(B,C)。结果
- >文件一和二​​

Return all Documents where at least one value of the tags array are IN("B", "C").
-> documents "one" and "two"

推荐答案

您可以结合使用加入运营商,这是用来形成嵌套的数组元素的交叉产品,在运营商。

You can combine the JOIN operator , which is used to form cross products with nested array elements, with the IN operator.

SELECT docs
FROM docs
JOIN tags IN docs.tags
WHERE tags IN ("B", "C")

请注意,由于您要创建一个跨产品,你会得到一个结果,对于每个匹配的子元素,而不是为每个文件。

Note that because you are creating a cross product, that you will get a result for each matching child element, rather than for each document.

另外,您可以将几个 ARRAY_CONTAINS 运营商,或者写一个UDF。

Alternatively you could combine several ARRAY_CONTAINS with OR operators, or write a UDF.

这篇关于DocumentDB使用数组查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆