通过Logic App和Cosmos DB中的PartitionKey不匹配在Cosmos DB中创建文档标头 [英] Create a document in Cosmos DB via Logic App and PartitionKey mismatch in document & header

查看:45
本文介绍了通过Logic App和Cosmos DB中的PartitionKey不匹配在Cosmos DB中创建文档标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试创建一个Azure Logic应用程序,该应用程序将在Cosmos DB集合内创建一个新记录以存储审阅结果.

So I'm trying to create an Azure Logic App which will create a new record inside a Cosmos DB collection to store review results.

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

I've created a Cosmos DB database (called icecream) + collection (called reviews). The PartitionKey of the reviews collection is /flavorIdentifier.

在我的Logic App中,我有一个插入新文档的步骤.

In my Logic App I have a step which inserts a new document.

代码看起来像这样.

"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

So, I'm posting the message to Cosmos DB

{
    "flavor": "My flavor",
    "flavorIdentifier": "3",
    "id": "4927042a-faa1-4e09-9c6d-d038ef659b25",
    "review": "Very satisfied"
}

如您所见,我还将分区键指定为与 flavorIdentifier 相同的值.我的猜测是这应该工作.但这不是

As you can see, I also specified the partition key to the same value as flavorIdentifier. My guess is this should just work. But it doesn't

我收到状态错误

从文档中提取的PartitionKey与标题中指定的键不匹配

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

这很奇怪,因为当检查原始输入和输出时,两者的值相同.我有什么要忽略的吗?

Which is strange, as both have the same value, also when checking the raw input and output. Is there anything I'm overlooking?

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

For completeness, the full input and output of this step.

失败步骤的原始输入.

{
    "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"
    }
}

有什么想法吗?

推荐答案

请在分区键周围添加双引号" ,对我来说很好.

Please add double quotation marks "" around your partition key and it works fine for me.

查看代码:

这篇关于通过Logic App和Cosmos DB中的PartitionKey不匹配在Cosmos DB中创建文档标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆