如何使用c#将json插入cosmos db集合 [英] how to insert json into cosmos db collection using c#

查看:108
本文介绍了如何使用c#将json插入cosmos db集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Json文件,我想将其存储在cosmos DB Collection中.如何使用C#添加完整的Json文件?是否有相同的客户端库?

I have a Json file which I wanted to store in a cosmos DB Collection. How can I add a complete Json file using C#? Is there any client library for the same?

我已经通过下面的URL Microsoft URL

I have already gone through the below URL Microsoft URL

但遇到以下问题

响应状态代码未指示成功:400子状态:1001原因:(消息:{错误":[从文档中提取的PartitionKey与标题中指定的不匹配"]} ActivityId:1ce4974b-0897- 4823-9c04-be3acf358d9b,请求URI:/apps/52181d0a-9f43-4346-861f-c74d77b2f8c4/services/9b95b2b5-d989-4cf5-a0f7-afc6b4e4292d/partitions/ef42b5fd-48d6-cas6-38069952309 ,RequestStats:RequestStartTime:2019-08-27T15:22:47.4097810Z,RequestEndTime:2019-08-27T15:22:47.4498208Z,尝试的区域数: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/ef42 -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).

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).

推荐答案

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

Seems like you are passing wrong partition key value.

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

Make sure to specify the partition key value and not the attribute i.e. you would write x-ms-documentdb-partitionkey: [ "value" ].

这篇关于如何使用c#将json插入cosmos db集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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