c# - 如何使用 C# 将 json 插入到 cosmos db 集合中

标签 c# json azure azure-cosmosdb

我有一个 Json 文件,我想将其存储在 cosmos DB 集合中。如何使用 C# 添加完整的 Json 文件?有同样的客户端库吗?

我已经浏览过以下网址Microsoft URL

但遇到以下问题

Response status code does not indicate success: 400 Substatus: 1001 Reason: (Message: {"Errors":["PartitionKey extracted from document doesn't match the one specified in the header"]}ActivityId: 1ce4974b-0897-4823-9c04-be3acf358d9b, Request URI: /apps/52181d0a-9f43-4346-861f-c74d77b2f8c4/services/9b95b2b5-d989-4cf5-a0f7-afc6b4e4292d/partitions/ef42b5fd-48d6-4536-952e-9309285d38b1/replicas/132090639069807943p/, RequestStats: RequestStartTime: 2019-08-27T15:22:47.4097810Z, RequestEndTime: 2019-08-27T15:22:47.4498208Z, Number of regions attempted: 1ResponseTime: 2019-08-27T15:22:47.4498208Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-eastus2-fd22.documents.azure.com:14122/apps/52181d0a-9f43-4346-861f-c74d77b2f8c4/services/9b95b2b5-d989-4cf5-a0f7-afc6b4e4292d/partitions/ef42b5fd-48d6-4536-952e-9309285d38b1/replicas/132090639069807943p/, LSN: 10, GlobalCommittedLsn: 10, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 1001, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#10, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Create, SDK: Windows/10.0.17134 cosmos-netstandard-sdk/3.1.4).

最佳答案

似乎您传递了错误的分区键值。

确保指定分区键值而不是属性,即您将编写 x-ms-documentdb-partitionkey: [ "value"]。

关于c# - 如何使用 C# 将 json 插入到 cosmos db 集合中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57678013/

相关文章:

java - 如何将json对象添加到同级的另一个json对象中?

Azure Function App 消耗,使用 Azure Blob 存储 V1 或 V2

azure - 宇宙数据库 : SQL API + Graph API -- Really multi-model?

azure - 使用 powershell 检查 Azure 存储帐户文件共享已用容量的快速方法

c# - 为什么 "decimal"不是有效的属性参数类型?

C# 获取设置与不获取设置

android - 如何使用 Listview 访问多个 JSONArray?

c# - 为什么这个 Union on two Dictionary 不起作用?

c# - 如何在 C# 中访问 WinRM

json - 如何从 Angular 响应式(Reactive)表单中删除字段?