如何在 Azure DocumentDB 中执行类似于 SQL join 的连接操作
How to perform join operation similar to SQL join in Azure DocumentDB
我在 Azure DocumentDB 中有一个集合,其中我使用一个名为 clusterName 的 JSON 属性 将文档聚集成 3 个集合。 3 组文档的模板有点像这样:
{
"clusterName": "CustomerInformation",
"id": "CustInfo1001",
"custName": "XXXX"
},
{
"clusterName": "ZoneInformation",
"id": "ZoneInfo5005",
"zoneName": "YYYY"
},
{
"clusterName": "CustomerZoneAssociation",
"id": "CustZoneAss9009",
"custId": "CustInfo1001",
"zoneId": "ZoneInfo5005"
}
如您所见,CustomerZoneAssociation 的文档链接了 CustomerInformation 和 ZoneInformation 的文档与他们的 Id 。在 CustomerZoneAssociation 集群中关联的 Id 的帮助下,我需要帮助从 CustomerInformation 和 ZoneInformation 集群中查询信息。我期望的查询结果是:
{
"clusterName": "CustomerZoneAssociation",
"id": "CustZoneAss9009",
"custId": "CustInfo1001",
"custName": "XXXX",
"zoneId": "ZoneInfo5005",
"zoneName": "YYYY"
}
请提出一个只需访问 DocumentDB 一次的解决方案
DocumentDB 不支持文档间 JOIN...相反,JOIN
关键字用于执行文档内叉积(与嵌套数组一起使用)。
我会推荐以下方法之一:
请记住,您不必像使用传统 RDBMS 那样规范化每个实体。可能值得重新审视您的数据模型,并在适当的时候对部分数据进行去规范化。还要记住,去规范化有其自身的权衡(散开写入与发出后续读取)。查看以下 SO 答案以阅读有关 tradeoffs between normalizing vs de-normalizing data.
的更多信息
编写一个存储过程来对单个网络请求中的一系列操作进行批处理。查看以下 SO 答案以获得 code sample on this approach.
我在 Azure DocumentDB 中有一个集合,其中我使用一个名为 clusterName 的 JSON 属性 将文档聚集成 3 个集合。 3 组文档的模板有点像这样:
{ "clusterName": "CustomerInformation", "id": "CustInfo1001", "custName": "XXXX" },
{ "clusterName": "ZoneInformation", "id": "ZoneInfo5005", "zoneName": "YYYY" },
{ "clusterName": "CustomerZoneAssociation", "id": "CustZoneAss9009", "custId": "CustInfo1001", "zoneId": "ZoneInfo5005" }
如您所见,CustomerZoneAssociation 的文档链接了 CustomerInformation 和 ZoneInformation 的文档与他们的 Id 。在 CustomerZoneAssociation 集群中关联的 Id 的帮助下,我需要帮助从 CustomerInformation 和 ZoneInformation 集群中查询信息。我期望的查询结果是:
{ "clusterName": "CustomerZoneAssociation", "id": "CustZoneAss9009", "custId": "CustInfo1001", "custName": "XXXX", "zoneId": "ZoneInfo5005", "zoneName": "YYYY" }
请提出一个只需访问 DocumentDB 一次的解决方案
DocumentDB 不支持文档间 JOIN...相反,JOIN
关键字用于执行文档内叉积(与嵌套数组一起使用)。
我会推荐以下方法之一:
请记住,您不必像使用传统 RDBMS 那样规范化每个实体。可能值得重新审视您的数据模型,并在适当的时候对部分数据进行去规范化。还要记住,去规范化有其自身的权衡(散开写入与发出后续读取)。查看以下 SO 答案以阅读有关 tradeoffs between normalizing vs de-normalizing data.
的更多信息
编写一个存储过程来对单个网络请求中的一系列操作进行批处理。查看以下 SO 答案以获得 code sample on this approach.