Challenge - 5 Problems
Key Condition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Query with simple partition key condition
Given a DynamoDB table named Orders with
Assuming
OrderID as the partition key, what will be the output of this key condition expression?OrderID = :orderIdAssuming
:orderId is set to 12345 and the table contains one item with OrderID 12345 and CustomerName 'Alice'.DynamoDB
KeyConditionExpression: 'OrderID = :orderId', ExpressionAttributeValues: { ':orderId': { N: '12345' } }
Attempts:
2 left
💡 Hint
Remember, the key condition expression must specify the partition key equality.
✗ Incorrect
In DynamoDB, the key condition expression must include the partition key with equality. Here, it matches the item with OrderID 12345 exactly.
❓ query_result
intermediate2:00remaining
Using sort key with BETWEEN in key condition
Consider a DynamoDB table Events with
With values:
The table has events for user1 on '2023-01-10', '2023-02-01', and '2023-01-20'.
UserID as partition key and EventDate as sort key (string in 'YYYY-MM-DD' format). What will this key condition expression return?UserID = :uid AND EventDate BETWEEN :start AND :endWith values:
:uid = 'user1':start = '2023-01-01':end = '2023-01-31'The table has events for user1 on '2023-01-10', '2023-02-01', and '2023-01-20'.
DynamoDB
KeyConditionExpression: 'UserID = :uid AND EventDate BETWEEN :start AND :end', ExpressionAttributeValues: { ':uid': { S: 'user1' }, ':start': { S: '2023-01-01' }, ':end': { S: '2023-01-31' } }
Attempts:
2 left
💡 Hint
BETWEEN works on sort keys to filter a range of values.
✗ Incorrect
The key condition filters items with UserID 'user1' and EventDate between '2023-01-01' and '2023-01-31', so it returns the two events within that date range.
📝 Syntax
advanced2:00remaining
Identify syntax error in key condition expression
Which option contains a syntax error in the DynamoDB key condition expression?
Attempts:
2 left
💡 Hint
Key condition expressions only allow AND, not OR.
✗ Incorrect
DynamoDB key condition expressions do not support OR operators. Option B uses OR, which is invalid syntax.
❓ query_result
advanced2:00remaining
Effect of missing partition key in key condition
What happens if you run a DynamoDB query with this key condition expression?
Given that
EventDate = :dateGiven that
EventDate is the sort key and UserID is the partition key.DynamoDB
KeyConditionExpression: 'EventDate = :date', ExpressionAttributeValues: { ':date': { S: '2023-01-01' } }
Attempts:
2 left
💡 Hint
Partition key equality is mandatory in key condition expressions.
✗ Incorrect
DynamoDB requires the partition key equality condition in key condition expressions. Omitting it causes a validation error.
🧠 Conceptual
expert2:00remaining
Understanding key condition expression limitations
Which statement correctly describes a limitation of DynamoDB key condition expressions?
Attempts:
2 left
💡 Hint
Think about what is mandatory and optional in key condition expressions.
✗ Incorrect
Key condition expressions require the partition key equality condition and optionally allow conditions on the sort key. They do not support OR or filtering on non-key attributes.