如何在Azure DocumentDB中执行类似于SQL连接的连接操作
我在Azure DocumentDB中有一个集合,其中我使用名为 clusterName 的JSON属性为每个文档将文档分为3组.这三组文档的模板如下所示:
I have a collection in Azure DocumentDB where in I have documents clustered into 3 sets using a JSON property called clusterName for each document. The 3 clusters of documents are templated somewhat like these:
{ "clusterName":"CustomerInformation", "id":"CustInfo1001", "custName":"XXXX" },
{ "clusterName": "CustomerInformation", "id": "CustInfo1001", "custName": "XXXX" },
{ "clusterName":"ZoneInformation", "id":"ZoneInfo5005", "zoneName":"YYYY" },
{ "clusterName": "ZoneInformation", "id": "ZoneInfo5005", "zoneName": "YYYY" },
{ "clusterName":"CustomerZoneAssociation", "id":"CustZoneAss9009", "custId":"CustInfo1001", "zoneId":"ZoneInfo5005" }
{ "clusterName": "CustomerZoneAssociation", "id": "CustZoneAss9009", "custId": "CustInfo1001", "zoneId": "ZoneInfo5005" }
您可以看到 CustomerZoneAssociation 的文档将 CustomerInformation 和 ZoneInformation 的文档及其ID链接在一起.在通过CustomerZoneAssociation群集中关联的ID从CustomerInformation和ZoneInformation群集中查询信息时,我需要帮助.我期望的查询结果是:
As you can see the document for CustomerZoneAssociation links the documents of CustomerInformation and ZoneInformation with their Id s. I need help in querying out information from CustomerInformation and ZoneInformation cluster with the help of their Id s associated in the CustomerZoneAssociation cluster. The result of the query I am expecting is:
{ "clusterName":"CustomerZoneAssociation", "id":"CustZoneAss9009", "custId":"CustInfo1001", "custName":"XXXX", "zoneId":"ZoneInfo5005", "zoneName":"YYYY" }
{ "clusterName": "CustomerZoneAssociation", "id": "CustZoneAss9009", "custId": "CustInfo1001", "custName": "XXXX", "zoneId": "ZoneInfo5005", "zoneName": "YYYY" }
请提出一个只需花一趟DocumentDB的解决方案
Please suggest a solution which would take only 1 trip to DocumentDB
DocumentDB不支持文档间的JOIN ...,相反,JOIN
关键字用于执行文档内的跨产品(与嵌套数组).
DocumentDB does not support inter-document JOINs... instead, the JOIN
keyword is used to perform intra-document cross-products (to be used with nested arrays).
我建议使用以下方法之一:
I would recommend one of the following approaches:
-
请记住,您不必像使用传统RDBMS一样规范每个实体.可能值得重新审视数据模型,并在适当的地方对部分数据进行规范化处理.还请记住,非规范化有其自身的取舍(散发写与发行跟进读).请查看以下SO答案,以详细了解权衡归一化与非归一化数据之间.
编写一个存储过程,以在单个网络请求中批处理一系列操作.在下面的代码示例中查看以下答案这种方法.
Write a stored procedure to batch a sequence of operations within a single network request. Checkout the following SO answer for a code sample on this approach.