azure - Cosmos DB 左连接

标签 azure azure-cosmosdb

Cosmos DB 的所有文档,看起来它只支持 JOIN 关键字,这似乎是一种 INNER JOIN

我有以下查询:

SELECT * FROM
(
    SELECT 
        DISTINCT(c.id),
        c.OtherCollection,
    FROM c
    JOIN s IN c.OtherCollection
)
AS c order by c.id

这工作正常并返回已填充 OtherCollection 的文档的数据。但它显然不会返回任何未填充的文档。

连接的原因是有时我会执行以下查询(查询是根据用户输入构建的)

SELECT * FROM
(
    SELECT 
        DISTINCT(c.id),
        c.OtherCollection,
    FROM c
    JOIN s IN c.OtherCollection
    WHERE s.PropertyName = 'SomeValue'
)
AS c order by c.id

问题是在这种情况下如何使用 LEFT JOIN 运算符?

最佳答案

您可以使用EXISTS语句模拟LEFT JOIN。 例如:

SELECT VALUE c 
FROM c
WHERE (
    (c.OtherCollection = null) OR EXISTS (--Like a "Left Join"
        SELECT null 
        FROM s IN c.OtherCollection
        WHERE s.PropertyName = 'SomeValue'
    )
)
--AND/OR Some other c Node conditions
order by c.id

关于azure - Cosmos DB 左连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57463395/

相关文章:

azure - 覆盖 Azure Cosmos DB 中的 ID 创建

azure - DocumentDB 用户定义的性能定价

扩展到更多实例后,Azure 网站保持禁用状态

azure - 是否可以将池规范移至 ADO YAML 中的模板中?

java - 如何使用 Java 和 Maven 实现 Microsoft Graph API

azure - DocumentDB UnauthorizedException : "The MAC signature found in the HTTP request is not the same as the computed signature."

azure - 如何更新 Cosmos DB 文档分区键元素?

azure - 延长 Azure 30 天试用期

postgresql - 为什么无法将标签添加到 terraform 模块中

azure-cosmosdb - 通过逻辑应用程序在 Cosmos DB 中创建文档,并且文档和标题中的 PartitionKey 不匹配