0
0
DynamoDBquery~10 mins

Transaction conditions in DynamoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a condition that the attribute 'status' must equal 'active' in a DynamoDB transaction.

DynamoDB
TransactItems: [{ Update: { Key: { id: '123' }, UpdateExpression: 'SET #s = :new', ConditionExpression: '#s = [1]', ExpressionAttributeNames: { '#s': 'status' }, ExpressionAttributeValues: { ':new': 'inactive', ':active': 'active' } } }]
Drag options to blanks, or click blank then click option'
A'inactive'
B'pending'
C'active'
D'deleted'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the new value 'inactive' instead of the current expected value 'active'.
Forgetting to put quotes around the string value.
2fill in blank
medium

Complete the code to ensure the transaction only proceeds if the attribute 'count' is less than 10.

DynamoDB
TransactItems: [{ Put: { Item: { id: '456', count: 1 }, ConditionExpression: 'attribute_exists(id) AND [1] < :max', ExpressionAttributeValues: { ':max': 10 } } }]
Drag options to blanks, or click blank then click option'
Avalue
Bid
Cstatus
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' or other unrelated attributes in the condition.
Omitting the attribute name in the condition expression.
3fill in blank
hard

Fix the error in the condition expression to check that attribute 'version' equals 3 before updating.

DynamoDB
TransactItems: [{ Update: { Key: { id: '789' }, UpdateExpression: 'SET version = version + 1', ConditionExpression: 'version = [1]' } }]
Drag options to blanks, or click blank then click option'
A3
B'3'
C:3
D#3
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Using placeholders incorrectly like ':3' or '#3'.
4fill in blank
hard

Fill both blanks to create a condition that attribute 'score' is greater than 50 and attribute 'level' is less than 10.

DynamoDB
ConditionExpression: '#sc [1] :minScore AND #lv [2] :maxLevel', ExpressionAttributeNames: { '#sc': 'score', '#lv': 'level' }, ExpressionAttributeValues: { ':minScore': 50, ':maxLevel': 10 }
Drag options to blanks, or click blank then click option'
A>
B<
C=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of comparison operators.
Swapping the operators for the two attributes.
5fill in blank
hard

Fill all three blanks to build a transaction condition that attribute 'status' equals 'pending', attribute 'attempts' is less than 5, and attribute 'priority' is greater than or equal to 1.

DynamoDB
ConditionExpression: '#st = [1] AND #at [2] :maxAttempts AND #pr [3] :minPriority', ExpressionAttributeNames: { '#st': 'status', '#at': 'attempts', '#pr': 'priority' }, ExpressionAttributeValues: { ':maxAttempts': 5, ':minPriority': 1 }
Drag options to blanks, or click blank then click option'
A'pending'
B<
C>=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around 'pending'.
Using wrong comparison operators like '=' instead of '<' or '>='.