gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:19:56 25 4
gpt4 key购买 nike

所以我正在尝试创建一个 Azure 逻辑应用程序,它将在 Cosmos DB 集合中创建一个新记录来存储审查结果。

我创建了一个 Cosmos DB 数据库(称为 icecream )+ 集合(称为 reviews )。 reviews 集合的 PartitionKey 是 /flavorIdentifier

PartitionKey

在我的逻辑应用程序中,我有一个插入新文档的步骤。
Logic App Step

代码看起来像这样。

"Create_review": {
"inputs": {
"body": {
"flavor": "@{body('JSON_parseren_2')?['flavor']}",
"flavorIdentifier": "@{body('JSON_parseren')?['itemOrdered']}",
"id": "@{guid()}",
"review": "@{body('E-mail_met_opties_verzenden')?['SelectedOption']}"
},
"headers": {
"x-ms-documentdb-raw-partitionkey": "@body('JSON_parseren')?['itemOrdered']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['documentdb']['connectionId']"
}
},
"method": "post",
"path": "/dbs/@{encodeURIComponent('icecream')}/colls/@{encodeURIComponent('reviews')}/docs"
},
"runAfter": {
"E-mail_met_opties_verzenden": [
"Succeeded"
]
},
"type": "ApiConnection"
},

所以,我将消息发布到 Cosmos DB
{
"flavor": "My flavor",
"flavorIdentifier": "3",
"id": "4927042a-faa1-4e09-9c6d-d038ef659b25",
"review": "Very satisfied"
}

如您所见,我还将分区键指定为与 flavorIdentifier 相同的值。
我的猜测是这应该有效。但它没有

我收到的错误状态

PartitionKey extracted from document doesn't match the one specified in the header



这很奇怪,因为它们具有相同的值,在检查原始输入和输出时也是如此。有什么我忽略的吗?

为完整起见,此步骤的完整输入和输出。

失败步骤的原始输入。
{
"host": {
"connection": {
"name": "/subscriptions/3b3729b4-021a-48b5-a2eb-47be0c7e7f44/resourceGroups/developerday-workshop/providers/Microsoft.Web/connections/documentdb"
}
},
"method": "post",
"path": "/dbs/icecream/colls/reviews/docs",
"headers": {
"x-ms-documentdb-raw-partitionkey": "3"
},
"body": {
"flavor": "My flavor",
"flavorIdentifier": "3",
"id": "4927042a-faa1-4e09-9c6d-d038ef659b25",
"review": "Very satisfied"
}
}

失败步骤的原始输出。
{
"statusCode": 400,
"headers": {
"x-ms-last-state-change-utc": "Wed,27 Mar 2019 05:03:54.568 GMT",
"lsn": "1",
"x-ms-schemaversion": "1.7",
"x-ms-quorum-acked-lsn": "1",
"x-ms-substatus": "1001",
"x-ms-current-write-quorum": "3",
"x-ms-current-replica-set-size": "4",
"x-ms-xp-role": "1",
"x-ms-global-Committed-lsn": "1",
"x-ms-number-of-read-regions": "0",
"x-ms-transport-request-id": "1",
"x-ms-cosmos-llsn": "1",
"x-ms-cosmos-quorum-acked-llsn": "1",
"x-ms-session-token": "1",
"x-ms-request-charge": "1.24",
"x-ms-serviceversion": "version=2.2.0.0",
"x-ms-activity-id": "bd428162-ec1a-4f50-879a-04b8ca0817a1",
"Strict-Transport-Security": "max-age=31536000",
"x-ms-gatewayversion": "version=2.2.0.0",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "false",
"Date": "Wed, 27 Mar 2019 11:39:57 GMT",
"Content-Length": "1149",
"Content-Type": "application/json"
},
"body": {
"code": "BadRequest",
"message": "Message: {\"Errors\":[\"PartitionKey extracted from document doesn't match the one specified in the header\"]}\r\nActivityId: bd428162-ec1a-4f50-879a-04b8ca0817a1, Request URI: /apps/9bc5d0cc-9b7c-4b1d-9be2-0fa2654271c4/services/9d84c048-383b-498e-8472-1f57da72135d/partitions/0f29761a-9ffc-4560-94ce-0328c3c79f92/replicas/131981366274575376p/, RequestStats: \r\nRequestStartTime: 2019-03-27T11:39:57.0795308Z, RequestEndTime: 2019-03-27T11:39:57.0995601Z, Number of regions attempted: 1\r\nResponseTime: 2019-03-27T11:39:57.0995601Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd21.documents.azure.com:16833/apps/9bc5d0cc-9b7c-4b1d-9be2-0fa2654271c4/services/9d84c048-383b-498e-8472-1f57da72135d/partitions/0f29761a-9ffc-4560-94ce-0328c3c79f92/replicas/131981366274575376p/, LSN: 1, GlobalCommittedLsn: 1, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 1001, RequestCharge: 1.24, ItemLSN: -1, SessionToken: 1, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Create\r\n, SDK: Microsoft.Azure.Documents.Common/2.2.0.0"
}
}

有什么想法吗?

最佳答案

请加双引号""在你的分区键周围,它对我来说很好用。

enter image description here

查看代码:

enter image description here

关于azure-cosmosdb - 通过逻辑应用程序在 Cosmos DB 中创建文档,并且文档和标题中的 PartitionKey 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55376489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com