azure - 匹配所有单词的 Cosmos DB json 数组

标签 azure azure-cosmosdb azure-cosmosdb-sqlapi

我需要一个查询,可以从单词列表中获取文档,例如,如果我使用


    select c from c join (SELECT distinct VALUE c.id FROM c JOIN word IN c.words WHERE  word in('word1',word2) and tag in('motorcycle')) ORDER BY c._ts desc

它将带来两个文档,我只想检索第一个文档,因为它匹配两个单词,而不仅仅是一个。

文档1

 "c": {
            "id": "d0f1723c-0a55-454a-9cf8-3884f2d8d61a",
            "words": [
                "word1",
                "word2",
                "word3",
             ]}

文档2

 "c": {
            "id": "d0f1723c-0a55-454a-9cf8-3884f2d8d61a",
            "words": [
                "word1",
                "word4",
                "word5",
             ]}

最佳答案

您应该能够在 WHERE 子句中使用两个 ARRAY_CONTAINS 表达式来覆盖这一点(并且不需要 JOIN):

SELECT c.id FROM c
WHERE ARRAY_CONTAINS(c.words, 'word1')
AND ARRAY_CONTAINS(c.words, 'word2')

这应该返回您的第一个文档的 ID。

关于azure - 匹配所有单词的 Cosmos DB json 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65484405/

相关文章:

Azure DevOps 动态发布管道创建

powershell - 如何为 Azure RM 订阅设置默认存储帐户

azure-cosmosdb - 如何在 Cosmos db 中分组和排序?

Azure Cosmos 文档数据库的 Java Api (SQL Api)

azure-cosmosdb - 使用一个 Cosmos DB 查询获取多个计数?

asp.net - 是否可以从 ASP MVC 项目执行 Azure PowerShell 脚本?

azure - IceCast 流身份验证

azure - 使用 EnableCrossPartitionQuery 的 CosmosDB CreateDocumentQuery 不会返回结果,但如果指定 PartitionKey 则会返回结果

azure - 使用 SQL 的 Cosmos DB 查询数组值

c# - Azure Cosmos DB 批量插入计算内部错误