【问题标题】:DocumentDB REST API: PartitionKey extracted from document doesn't matchDocumentDB REST API:从文档中提取的 PartitionKey 不匹配
【发布时间】:2017-03-21 06:29:16
【问题描述】:

我正在尝试使用 PHP(缺少官方 API 包装器)通过 REST 将 JSON 文档插入 DocumentDB。现在,似乎对于 DocumentDB 中的任何集合都必须使用分区键,但我找不到记录的 REST API。

我得到以下错误作为回报:

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

我尝试插入的 JSON 文档如下所示:

{ id:"1", ... "domain":"domain.com" }

在 Azure 中,我使用以下分区键定义了集合:

/domain

在发送 REST 请求时,我会发送以下标头:

x-ms-documentdb-partitionkey: [ "domain" ]

我在这里错过了什么?

【问题讨论】:

  • 您需要指定分区键值而不是属性,即您将编写x-ms-documentdb-partitionkey: [ "domain.com" ]。请试试这个。
  • 成功了!!非常感谢! (请将您的回复添加为答案 - 不要评论 - 这样我可以设置接受/已解决)
  • 澄清:分区集合需要分区键,而不是单分区集合。

标签: azure azure-cosmosdb


【解决方案1】:

对于 x-ms-documentdb-partitionkey 值,您需要指定分区键值 ("domain.com") 而不是分区键属性 ("domain")。

x-ms-documentdb-partitionkey: [ "domain.com" ]

执行此操作后,将返回与此分区键值匹配的文档。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    相关资源
    最近更新 更多