I am trying to update item by email
(HASH PK), id
and verifyToken
. My query looks like this:
params =
TableName: 'users'
Key:
email:
S: '[email protected]'
AttributeUpdates:
verified:
Action: 'PUT'
Value:
BOOL: true
verifyToken:
Action: 'DELETE'
ExpressionAttributeValues:
':id': { S: '123' }
':verifyToken': { S: 'XXX' }
ConditionExpression: 'id = :id and verifyToken = :verifyToken'
dynamodb.updateItem(params)
In other words I want to update Item where email = '[email protected]' AND id = '123' AND verifyToken = 'XXX', but I am getting following error:
Can not use both expression and non-expression parameters in the same request:
Non-expression parameters: {AttributeUpdates}
Expression parameters: {ConditionExpression}
To update an existing item in an Amazon DynamoDB table, you use the UpdateItem operation. You must provide the key of the item that you want to update. You must also provide an update expression, indicating the attributes that you want to modify and the values that you want to assign to them.
You cannot update the primary key attributes using UpdateItem. Instead, delete the item and use PutItem to create a new item with new attributes. The UpdateItem operation includes an Action parameter, which defines how to perform the update. You can put, delete, or add attribute values.
Can we update the sort key in DynamoDB? No, you can not update the sort key after the table is provisioned. However, you can create a new table and put the existing data in the newly created table, and delete the old table.
When you add an item, the primary key attributes are the only required attributes. Attribute values cannot be null. Empty String and Binary attribute values are allowed. Attribute values of type String and Binary must have a length greater than zero if the attribute is used as a key attribute for a table or index.
You are combining legacy parameters (AttributeUpdates
), which are only there for backwards compatibility, with expression parameters (ConditionExpression
). As the error states, you cannot do that.
You need to use an UpdateExpression
in conjunction with your ConditionExpression
.
It would be something like this. You may need to use expression attribute names/values in the UpdateExpression
:
ConditionExpression: 'id = :id and verifyToken = :verifyToken'
UpdateExpression: 'SET verified = true, REMOVE verifyToken'
See this documentation for more information on update expressions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With