azure-cosmosdb

Replace specific element in array using partial document update in Cosmos DB without knowing it's index


Is it possible to replace a specific element in an array in a Cosmos document using partial document update without knowing it's index?

Given the example json document, is it possible to replace the element in the array "elements" where name is "B", without knowing the index of the element using a partial document update in Cosmos DB?

{
    "elements": [
        {
            "name": "A",
            "value": 5
        },
        {
            "name": "B",
            "value": 3
        },
        {
            "name": "C",
            "value": 8
        }
    ]
}

No information found in the Microsoft documentation


Solution

  • No, PATCH requires you to pass the specific index of the object needs to be updated and it is mentioned in the documentation. We are working on enabling this particular feature, However as an alternative, you should look at Conditional Patch