Search code examples
c#jsonazureazure-cosmosdb

how to insert json into cosmos db collection using c#


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?

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"]}

How do I resolve it?


I have reference this tutorial:

Quickstart - .NET client library - Azure Cosmos DB for NoSQL | Microsoft Learn


Solution

  • 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" ].