UpdateItem

Updates attributes of an existing item or creates a new item. Supports atomic updates: SET (assign), REMOVE (delete attribute), ADD (increment number), DELETE (remove from set).

Syntax

dynamodb
await docClient.send(new UpdateCommand({ TableName, Key, UpdateExpression, ExpressionAttributeValues }))

Example

dynamodb
await docClient.send(new UpdateCommand({
  TableName: 'Users',
  Key: { PK: 'USER#alice', SK: 'PROFILE' },
  UpdateExpression: 'SET lastLogin = :ts ADD loginCount :one',
  ExpressionAttributeValues: { ':ts': new Date().toISOString(), ':one': 1 },
}));