Recall & Review
beginner
What does the ADD expression do in DynamoDB?
The ADD expression increases (or decreases) the value of a numeric attribute by a specified amount. It can also add elements to a set attribute.
Click to reveal answer
beginner
How do you increment a numeric attribute named 'counter' by 1 using the ADD expression?
Use the UpdateExpression: <br>
ADD counter :inc<br>where :inc is a value of 1 in ExpressionAttributeValues.Click to reveal answer
intermediate
Can the ADD expression be used to decrement a numeric attribute in DynamoDB?
Yes, by adding a negative number. For example,
ADD counter :dec where :dec is -1 will decrement the counter by 1.Click to reveal answer
intermediate
What happens if the attribute does not exist when you use ADD to increment it?
DynamoDB creates the attribute and sets it to the increment value. For example, if 'counter' does not exist and you ADD 1, 'counter' becomes 1.
Click to reveal answer
advanced
Is the ADD expression atomic in DynamoDB updates?
Yes, the ADD operation is atomic, meaning it safely increments or decrements the attribute even if multiple updates happen at the same time.
Click to reveal answer
Which DynamoDB UpdateExpression syntax increments a numeric attribute 'score' by 5?
✗ Incorrect
The correct syntax uses ADD with a placeholder value, e.g.,
ADD score :val where :val is 5.What value should you provide to decrement a numeric attribute by 3 using ADD?
✗ Incorrect
You provide a negative number, so
-3 will decrement the attribute by 3.If the attribute 'visits' does not exist, what will ADD visits :inc with :inc = 1 do?
✗ Incorrect
DynamoDB creates the attribute and sets it to the increment value.
Is the ADD operation in DynamoDB atomic?
✗ Incorrect
ADD is atomic, so concurrent updates safely increment or decrement the attribute.
Which data types can the ADD expression modify in DynamoDB?
✗ Incorrect
ADD can increment numeric attributes and add elements to set attributes.
Explain how the ADD expression works for incrementing a numeric attribute in DynamoDB.
Think about how you tell DynamoDB to add a number to an attribute safely.
You got /4 concepts.
Describe how you would decrement a numeric attribute using the ADD expression in DynamoDB.
Remember ADD can add negative values to subtract.
You got /3 concepts.