Challenge - 5 Problems
Partition Key Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Querying items by partition key
Given a DynamoDB table named Orders with
OrderID as the partition key, what will be the output of this query if the table contains three orders with OrderID values '1001', '1002', and '1003'?DynamoDB
const params = {
TableName: 'Orders',
KeyConditionExpression: 'OrderID = :id',
ExpressionAttributeValues: {
':id': '1002'
}
};
// Assume docClient.query(params).promise() is called and returns ItemsAttempts:
2 left
💡 Hint
Remember, querying by partition key returns all items with that key.
✗ Incorrect
The query filters items where OrderID equals '1002'. Only the order with OrderID '1002' is returned.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in DynamoDB query
Which option contains a syntax error in the DynamoDB query to get items by partition key 'UserID' with value 'user123'?
DynamoDB
const params = {
TableName: 'Users',
KeyConditionExpression: 'UserID = :uid',
ExpressionAttributeValues: {
':uid': 'user123'
}
};Attempts:
2 left
💡 Hint
Check the commas between object properties carefully.
✗ Incorrect
The provided code has correct JavaScript syntax with all necessary commas present.
❓ optimization
advanced2:30remaining
Optimizing a query by partition key with a sort key
You have a DynamoDB table Messages with partition key
UserID and sort key Timestamp. You want to query all messages for user 'user42' sent after '2023-01-01'. Which query is the most efficient?Attempts:
2 left
💡 Hint
Use KeyConditionExpression to filter by partition and sort keys efficiently.
✗ Incorrect
Option A uses KeyConditionExpression with both partition and sort key conditions, which is efficient. Options A and C use FilterExpression which filters after reading data, less efficient. Option A scans the whole table, least efficient.
🔧 Debug
advanced2:00remaining
Debugging a query that returns no results
A developer runs this DynamoDB query to get items with partition key 'ProductID' = 'P123', but gets an empty result. What is the most likely cause?
DynamoDB
const params = {
TableName: 'Products',
KeyConditionExpression: 'ProductID = :pid',
ExpressionAttributeValues: {
':pid': 'p123'
}
};Attempts:
2 left
💡 Hint
DynamoDB partition keys are case sensitive.
✗ Incorrect
DynamoDB keys are case sensitive. Using 'p123' instead of 'P123' causes no matching items.
🧠 Conceptual
expert2:30remaining
Understanding query behavior with composite keys
In a DynamoDB table with partition key
CustomerID and sort key OrderDate, which statement is true about querying by partition key only?Attempts:
2 left
💡 Hint
Think about how DynamoDB organizes items with composite keys.
✗ Incorrect
Querying by partition key alone returns all items with that key, regardless of sort key values.