Azure Cosmos DB syntax for REPLACE method

Viewed 796

I'm working with the Cosmos SDK in my my Node.js app. I've been able to query the database successfully but I'm having trouble with the REPLACE method. I'm wanting to update a single item in the database either by the unique 'id' field or the build in '_rid' field.

Here is the how I currently have it formatted (which returns the error: Entity with the specified id does not exist in the system):

const { resource: updatedItem } = await client.database(databaseId).container(contianerId).item('2INhAI1fcdkSAAAAERFAAA==', 'TX').replace(newJsonObject);

Sample Item:
'state' is the partition key

{
    "DateTime": "01-28-19 11:55:48",
    "id": "15",
    "resolved": false,
    "state": "TX",
    "_rid": "2INhAI1fcdkSAAAAAAAAAA==",
    "_self": "dbs/2INhAA==/colls/2INhAI1fcdk=/docs/2INhAI1fcdkSAAAAAAAAAA==/",
    "_etag": "\"fd03208d-0000-0700-0000-5fc68a550000\"",
    "_attachments": "attachments/",
    "_ts": 1606847061
}
1 Answers

This ended up being the correct syntax for what I needed:

const { resource: updatedItem } = await client.database(databaseId).container(contianerId).item('15', 'TX').replace(newJsonObject);

where the value for the id and the value for the predefined partition key (state in my example) are the properties provided for the item.

Related