0
0
DynamoDBquery~5 mins

ADD expression for numeric increment in DynamoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AADD score :val
BSET score = score + 5
CADD score 5
DSET score + 5
What value should you provide to decrement a numeric attribute by 3 using ADD?
A0
B3
C-3
DCannot decrement with ADD
If the attribute 'visits' does not exist, what will ADD visits :inc with :inc = 1 do?
ACreate 'visits' with value 1
BReturn an error
CIgnore the update
DSet 'visits' to 0
Is the ADD operation in DynamoDB atomic?
AOnly when used with SET
BNo, it can cause conflicts
COnly for string attributes
DYes, it prevents race conditions
Which data types can the ADD expression modify in DynamoDB?
AOnly numeric attributes
BNumeric attributes and sets
COnly string attributes
DAll attribute types
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.