2

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
}
2
  • 1
    You should be querying id, not _rid. What issue are you having, querying by id? Perhaps edit your question to show that query, and what error you receive? Commented Jan 1, 2021 at 6:17
  • 1
    Thanks, I got it working by simply using the string value for id instead of _rid Commented Jan 1, 2021 at 16:12

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.