使用Logic Apps更新CosmosDB文档报分区键不匹配等错误咨询
问题根因分析
- 错误1:
PartitionKey extracted from document doesn't match the one specified in the header
你在请求头中传入的x-ms-documentdb-raw-partitionkey参数格式不符合要求。该参数需要传入JSON序列化后的分区键值,由于你集合的分区键id是字符串类型,直接填写12347会被识别为数字类型,和文档中字符串格式的"12347"类型不匹配,触发报错。 - 错误2:
One of the specified inputs is invalid
你省略了请求体中的id字段,该字段既是Cosmos DB文档的必填系统字段,也是你集合的分区键字段,缺失会直接判定为输入非法。
解决方案
按以下规则调整请求即可:
- 修正
x-ms-documentdb-raw-partitionkey头的取值:字符串类型的分区键值需要用双引号包裹,转义后取值为"\"12347\"";如果是在Logic Apps可视化配置界面填写分区键值,直接输入带双引号的"12347"即可,不要填写id、/id这类分区键路径。 - 请求体中必须保留
id字段,取值和分区键取值保持类型、内容完全一致。
修正后的完整请求示例:
{ "method": "post", "headers": { "x-ms-documentdb-is-upsert": "True", "x-ms-documentdb-raw-partitionkey": "\"12347\"" }, "path": "/dbs/bc-gamification-management/colls/bcpoints/docs", "host": { "connection": { "name": "<omitted as this shouldn't matter>" } }, "body": { "curr_point": 500, "id": "12347", "overall_point": 1400 } }
内容的提问来源于stack exchange,提问作者Cbennhsmwhs
相关产品推荐
相关产品推荐

