Rakesh Kumar
Rakesh Kumar

Reputation: 3149

Cosmos DB- "Resource Not Found error - while updating partition key property"

I am getting below error while updating the partition key field's value.

[7/8/2020 2:02:00 PM] [Error] - Exception while processing AddOrUpdateUserSettings [7/8/2020 2:02:00 PM] Executed 'AddOrUpdateUserSettings' (Failed, Id=caa3fab3-aece-43b2-9c16-bb1f4b78ec88) [7/8/2020 2:02:00 PM] System.Private.CoreLib: Exception while executing function: AddOrUpdateUserSettings. Microsoft.Azure.Cosmos.Client: Response status code does not indicate success: NotFound (404); Substatus: 0; ActivityId: 56c44578-b7c0-4cc9-aac8-5fc331371512; Reason: ({ [7/8/2020 2:02:00 PM] "Errors": [ [7/8/2020 2:02:00 PM] "Resource Not Found" [7/8/2020 2:02:00 PM] ] [7/8/2020 2:02:00 PM] });.

Here is my cosmos db item json format:

{
    "id": "dfb2ac12-13e3-460a-ad12-4ea9c7e8ca8c",
    "UserUUId": "DevStreamuser2",
    "PreferredLanguage": "en-US",
    "DateFormat": "dd/MM/yy",
    "TimeFormat": "hh:mm",
    "Created": "2020-07-08T09:16:35.3093774Z",
    "Updated": "2020-07-08T13:49:57.6835166Z",
    "_rid": "7Sx-AJVl4ysDAAAAAAAAAA==",
    "_self": "dbs/7Sx-AA==/colls/7Sx-AJVl4ys=/docs/7Sx-AJVl4ysDAAAAAAAAAA==/",
    "_etag": "\"00000000-0000-0000-552e-aad7ccd101d6\"",
    "_attachments": "attachments/",
    "_ts": 1594216197
}

"PreferredLanguage" property is a partition key. I am getting this error while trying to update the value for this property.

Below is my update method and also i am using cosmos DB SDK.

  public async Task<ItemResponse<T>> UpdateItemAsync(string id, T item)
        {
            return await _container.ReplaceItemAsync<T>(item, id);
        }

Upvotes: 0

Views: 884

Answers (1)

AnuragSharma-MSFT
AnuragSharma-MSFT

Reputation: 692

As of now, we cannot update the partition key of a document in a container.

Refer the link that mentions "If a property is your partition key, you can't update that property's value."

However, you can create a new document and remove the existing one in case you need to achieve above operation.

Upvotes: 1

Related Questions