Can I write an UPDATE
statement for Azure Cosmos DB? The SQL API supports queries, but what about updates?
In particular, I am looking to update documents without having to retrieve the whole document. I have the ID for the document and I know the exact path I want to update within the document. For example, say that my document is
{
"id": "9e576f8b-146f-4e7f-a68f-14ef816e0e50",
"name": "Fido",
"weight": 35,
"breed": "pomeranian",
"diet": {
"scoops": 3,
"timesPerDay": 2
}
}
and I want to update diet.timesPerDay
to 1 where the ID is "9e576f8b-146f-4e7f-a68f-14ef816e0e50"
. Can I do that using the Azure SQL API without completely replacing the document?
You can use Patch API for partial updates. Refer: https://learn.microsoft.com/en-us/azure/cosmos-db/partial-document-update