Introduction
You can change many parts of a database item at once to save time and keep data correct.
Jump into concepts and practice - no test required
UpdateExpression: "SET attribute1 = :val1, attribute2 = :val2 REMOVE attribute3 ADD attribute4 :val4 DELETE attribute5 :val5" ExpressionAttributeValues: { ":val1": value1, ":val2": value2, ":val4": value4, ":val5": value5 }
UpdateExpression: "SET age = :newAge, city = :newCity REMOVE oldAddress ADD points :pointsToAdd" ExpressionAttributeValues: { ":newAge": 30, ":newCity": "Seattle", ":pointsToAdd": 10 }
UpdateExpression: "SET status = :newStatus DELETE tags :tagsToRemove" ExpressionAttributeValues: { ":newStatus": "active", ":tagsToRemove": {"tag1", "tag2"} }
UpdateItem {
TableName: "Players",
Key: { "PlayerID": { S: "player123" } },
UpdateExpression: "SET Level = :newLevel, LastLogin = :loginTime REMOVE OldBadge ADD Score :scoreIncrease",
ExpressionAttributeValues: {
":newLevel": { N: "5" },
":loginTime": { S: "2024-06-01T10:00:00Z" },
":scoreIncrease": { N: "50" }
},
ReturnValues: "UPDATED_NEW"
}score by adding 10 in a DynamoDB update expression?SET age = age + :inc REMOVE nickname ADD points :pts DELETE tags :oldTagsage = 30, nickname = 'Sam', points = 5, and tags = {'red', 'blue'} with :inc = 2, :pts = 3, and :oldTags = {'blue'}?SET name = :n ADD age :a REMOVE points, DELETE tags :tstock by 5discontinuednewTag to a set attribute tags