Complete the code to add a condition that the attribute 'status' must equal 'active' in a DynamoDB transaction.
TransactItems: [{ Update: { Key: { id: '123' }, UpdateExpression: 'SET #s = :new', ConditionExpression: '#s = [1]', ExpressionAttributeNames: { '#s': 'status' }, ExpressionAttributeValues: { ':new': 'inactive', ':active': 'active' } } }]The condition expression requires the 'status' attribute to be 'active' before updating. So, the correct value is 'active'.
Complete the code to ensure the transaction only proceeds if the attribute 'count' is less than 10.
TransactItems: [{ Put: { Item: { id: '456', count: 1 }, ConditionExpression: 'attribute_exists(id) AND [1] < :max', ExpressionAttributeValues: { ':max': 10 } } }]The condition checks that 'count' is less than 10 before putting the item. So 'count' is the correct attribute.
Fix the error in the condition expression to check that attribute 'version' equals 3 before updating.
TransactItems: [{ Update: { Key: { id: '789' }, UpdateExpression: 'SET version = version + 1', ConditionExpression: 'version = [1]' } }]The condition expression compares the attribute 'version' to the number 3, so the value should be the number 3 without quotes or symbols.
Fill both blanks to create a condition that attribute 'score' is greater than 50 and attribute 'level' is less than 10.
ConditionExpression: '#sc [1] :minScore AND #lv [2] :maxLevel', ExpressionAttributeNames: { '#sc': 'score', '#lv': 'level' }, ExpressionAttributeValues: { ':minScore': 50, ':maxLevel': 10 }
The condition requires 'score' to be greater than 50 and 'level' to be less than 10, so the operators are '>' and '<'.
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.
ConditionExpression: '#st = [1] AND #at [2] :maxAttempts AND #pr [3] :minPriority', ExpressionAttributeNames: { '#st': 'status', '#at': 'attempts', '#pr': 'priority' }, ExpressionAttributeValues: { ':maxAttempts': 5, ':minPriority': 1 }
The condition requires 'status' to be 'pending' (string with quotes), 'attempts' less than 5, and 'priority' greater than or equal to 1.