Reputation: 1128
I am trying to delete all records which have the attribute "code" from a DynamoDB table. Here my params:
var params = {
TableName: table,
Key:{
"email": "email",
},
ConditionExpression:"attribute_exists(code)",
};
This is the error:
{
"message": "The conditional request failed",
"code": "ConditionalCheckFailedException",
"time": "2021-11-12T09:01:04.205Z",
"requestId": "e1d74c46-86a0-4f14-8c62-186102f2aff3",
"statusCode": 400,
"retryable": false,
"retryDelay": 36.80819226584606
}
An example record looks like this:
email - first_name - last_name - hash - code - confirmed
[email protected] - Bob - Mann - $2b$10$5/x6BkCks6ndXSr/GRhLgOPk.ettTv3lYpglbZbGnM7FXPX5VRFCe - undefined - undefined
Upvotes: 1
Views: 1811
Reputation: 8925
According to the documentation:
ConditionalCheckFailedException Message: The conditional request failed.
You specified a condition that was evaluated to be false. For example, you might have tried to perform a conditional update on an item, but the actual value of the attribute did not match the expected value in the condition.
OK to retry? No
So the problem is with the ConditionExpression
, the code
attribute does not exist in some records or it exists with undefined
value. try to change attribute_exists
with attribute_type
:
var params = {
TableName: table,
Key:{
"email": "email",
},
ConditionExpression:"attribute_type(code, S)",
};
The second parameter:
read more on comparison and function on amazondynamodb.
Upvotes: 2