如何解决逻辑应用程序到 CosmosDB - 从文档中提取的 PartitionKey 与标头中指定的不匹配
我在逻辑应用程序中使用 CosmosDB 连接器将记录插入到数据库中。我的容器名称是 ordersContainer。这是我的文档:
{
"id": "98327158-59d3-4b5b-8c36-0b7c6270c18e","item": {
"headers": {
"salesNumber": "LXG995","dateTime": "12/23/2020 6:24:40 PM","locationId": "DDD444","locationName": "Wide World Importers","locationAddress": "645 Roosevelt Avenue","locationPostcode": "98121","totalCost": "424.55","totalTax": "42.455"
},"details": [
{
"productId": "0f5a0fe8-4506-4332-969e-699a693334a8","quantity": "20","unitCost": "15.99","totalCost": "319.8","totalTax": "31.98","productName": "Beer","productDescription": "Hey this isn't ice cream!"
},{
"productId": "76065ecd-8a14-426d-a4cd-abbde2acbb10","quantity": "10","unitCost": "4.49","totalCost": "44.9","totalTax": "4.49","productName": "Gone Bananas","productDescription": "I'm not sure how appealing banana ice cream really is."
},{
"productId": "551a9be9-7f1c-447d-83ee-b18f5a6fb018","quantity": "15","unitCost": "3.99","totalCost": "59.85","totalTax": "5.985","productName": "Matcha Green Tea","productDescription": "Green tea ice cream is good for you because it is green."
}
]
}
}
在我的容器中,我的分区键是 /salesNumber,而在我的连接器中,我有“salesNumber”(用双引号括起来。但是,我收到了这个错误:
"code": "BadRequest","message": "Message: {\"Errors\":[\"PartitionKey extracted from document doesn't match the one specified in the header\"]}\r\nActivityId: ba051769-46cc-4890-b199-c65841f3c0da,Request URI: /apps/a13f0c17-4c1e-488f-a4f7-e0fb0c98bb56/services/4b64d4a5-e7e4-4141-a4a1-5a53ab79bc4b/partitions/1108ee0f-f7e4-4572-b6f8-7c63bea5c122/replicas/132551652008533238p/,RequestStats: \r\nRequestStartTime: 2021-01-17T14:21:22.5778297Z,RequestEndTime: 2021-01-17T14:21:22.5778297Z,Number of regions attempted:1\r\nResponseTime: 2021-01-17T14:21:22.5778297Z,StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-eastus1-fd59.documents.azure.com:14308/apps/a13f0c17-4c1e-488f-a4f7-e0fb0c98bb56/services/4b64d4a5-e7e4-4141-a4a1-5a53ab79bc4b/partitions/1108ee0f-f7e4-4572-b6f8-7c63bea5c122/replicas/132551652008533238p/,LSN: 5,GlobalCommittedLsn: 5,PartitionKeyRangeId: 0,IsValid: True,StatusCode: 400,SubStatusCode: 1001,RequestCharge: 1.24,ItemLSN: -1,SessionToken: 5,UsingLocalLSN: False,TransportException: null,ResourceType: Document,OperationType: Upsert\r\n,SDK: Microsoft.Azure.Documents.Common/2.11.0"
我不知道为什么说从文档(应该是上面的文档)中提取的 PartitionKey 与标题中的不匹配。好吧,文档中不是列出了标题吗?
感谢任何帮助!
谢谢!
解决方法
从文档中提取的 PartitionKey 与指定的不匹配 在标题中
此错误是由连接器中的分区键值与文档中的值不同引起的。在您的情况下,您的分区键是 /salesNumber
,因此您的连接器中的分区键值应该是 "LXG995"
,而不是“salesNumber”(用双引号括起来)。
问题是,我放入容器的文档在 item/headers/salesnumber 层次结构中有 salesNumber。没有跟上 Cosmos 如何做事的速度,我只是认为它会将那条数据作为分区键插入到记录中。
然而,我发现我必须将分区键设为“item/headers/salesNumber”,而不仅仅是“/salesNumber”。
我确实需要使用 salesNumber 作为分区键,以说明他们可能是来自该客户的多个订单,由他们的 salesNumber 标识。
谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。