how to insert json into cosmos db collection using c#

大城市里の小女人 提交于 2020-05-30 07:42:06

问题


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?

I have already gone through the below URL Microsoft URL

but getting below issue with it

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


回答1:


Seems like you are passing wrong partition key value.

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



来源:https://stackoverflow.com/questions/57678013/how-to-insert-json-into-cosmos-db-collection-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!