Hi everyone,
I have been having some issues with deleting an item when pasing ConditionExpressions.
This is my params that is passed into the DeleteCommand.
I am expecting this to delete the Item below, but everytime, I have been getting ConditionalCheckFailedException: The conditional request failed error.
const input: DeleteCommandInput = { TableName: 'TABLE_NAME', ConditionExpression: 'PK = :v1 and begins_with(SK, :v2)', ExpressionAttributeValues: { ':v1': 'USER#0ee34e40-c739-4bbd-b72b-9361a54db2b5#STUDENT#111', ':v2': 'TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51', }, Key: { PK: 'USER#0ee34e40-c739-4bbd-b72b-9361a54db2b5#STUDENT#111', SK: 'TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51', }, };
This is a sample of the Item that I would like to delete. As you can see,
PK = "USER#0ee34e40-c739-4bbd-b72b-9361a54db2b5#STUDENT#111"
, which is an exact of PK that I am passing in as :v1 and PK above.
SK = TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51#DATE#1700671174102"
, which starts with what I passed in above too.
{ "PK": "USER#0ee34e40-c739-4bbd-b72b-9361a54db2b5#STUDENT#111", "SK": "TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51#DATE#1700671174102", "GSI1PK": "USER#0ee34e40-c739-4bbd-b72b-9361a54db2b5#FORM#E26", "GSI1SK": "TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51#DATE#1700671174102", "type": "ACT", "id": "414fbe9f-1675-47a1-9c3d-f40cb7a25c51", "formId": "E26", "classId": "123", "className": "class1", "studentId": "111", "studentName": "student1", "userId": "0ee34e40-c739-4bbd-b72b-9361a54db2b5", "createdAt": "2023-09-09T23:30:50.565Z" }
Any one have any ideas why this is failing to match?
Love to get some suggestions.
Thank you!
Oh because in the table I have SK as TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51#DATE#1700671174102 (composed of testId and Date) and I would like to find SK that begins with TEST#414fbe9f-1675-47a1-9c3d-f40cb7a25c51 (testId only).
Is this the wrong way about deleting an item? Just want to delete an item that matches PK and SK that starts with something.
Just found out that I can't do ConditionExpression of PK and SK. Thank you for the clue