question

YaswanthChandraDuggirala-5507 avatar image
0 Votes"
YaswanthChandraDuggirala-5507 asked SaurabhSharma-msft commented

Azure Cosmos DB - .NET SDK - container.PatchItemAsync 404 Resource Not Found

Hello,

I'm updating a JSON item in a Container using*container.PatchItemAsync* but I'm receiving 404 error - Resource Not Found.

And Partition Key is /id and below is the sample code

List<PatchOperation> patchOperations = new List<PatchOperation>();
patchOperations.Add(PatchOperation.Set("/latest", 100));

ItemResponse<dynamic> item = await container.PatchItemAsync<dynamic>(
"30abb6e0-1e8c-xxxx-xxxx-xxxxxxxxxxxx",
new PartitionKey("id"),
patchOperations
);

azure-cosmos-db
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yeah, Got it. For PartitionKey I need to pass Value. Thanks @SaurabhSharma-msft . Issue is resolved

1 Vote 1 ·
SaurabhSharma-msft avatar image SaurabhSharma-msft YaswanthChandraDuggirala-5507 ·

anonymous user - Great Thanks for the confirmation
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

Thanks
Saurabh

0 Votes 0 ·

@yaswanthchandraduggirala-5507,
Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

Thanks
Saurabh

0 Votes 0 ·

1 Answer

SaurabhSharma-msft avatar image
1 Vote"
SaurabhSharma-msft answered SaurabhSharma-msft commented

Hi anonymous user,

Thanks for using Microsoft Q&A !!
If my understanding is correct, you are getting error while trying to update a document using container.PatchItemAsync method using CosmosDB .NET SDK.
I have tried this in my environment and it worked fine using your code.

 List<PatchOperation> patchOperations = new List<PatchOperation>();
             patchOperations.Add(PatchOperation.Set("/Property1", "Patched"));
    
             try
             {
                 ItemResponse<dynamic> item = await container.PatchItemAsync<dynamic>(
                 "order1",
                 new PartitionKey("partitionKey1"),
                 patchOperations
                 );
             }
             catch (Exception e)
             {
                 Console.WriteLine(e);
    
             }

Before Patch:
187712-image.png

Result:
187624-image.png

I believe you are passing the attribute which is being used as a partition key instead of passing PartitionKey for the item. However, can you please make sure that you are passing the correct Partition Key for the item.

You could further look into this document to troubleshoot any other potential causes of this error.

Please let me know if you have any questions.

Thanks
Saurabh


image.png (30.3 KiB)
image.png (21.1 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi anonymous user,
You could further look into this document to troubleshoot any other potential causes of this error.

Thanks
Saurabh

0 Votes 0 ·

@YaswanthChandraDuggirala-5507,

Please let me know if you find above reply useful. If yes, please 'Accept the answer' for the above reply. This will help other community members facing similar query to refer to this solution. Thanks.

Thanks
Saurabh

0 Votes 0 ·