0
0
DynamoDBquery~20 mins

Key-value and document store model in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Key-Value DynamoDB Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Query Result: Retrieving an Item by Primary Key

You have a DynamoDB table named Users with UserID as the primary key. Which query will return the item with UserID equal to 123?

AGetItem with Key = {"UserID": {"N": "123"}}
BQuery with KeyConditionExpression = "UserID = :id" and ExpressionAttributeValues = {":id": {"N": "123"}}
CScan with FilterExpression = "UserID = :id" and ExpressionAttributeValues = {":id": {"S": "123"}}
DUpdateItem with Key = {"UserID": {"N": "123"}}
Attempts:
2 left
💡 Hint

Use the simplest method to get an item by its primary key without scanning the whole table.

🧠 Conceptual
intermediate
1:30remaining
Understanding Partition Keys in DynamoDB

Which statement best describes the role of a partition key in a DynamoDB table?

AIt uniquely identifies each item and determines the partition where the item is stored.
BIt is used only for sorting items within a partition.
CIt is optional and only used for indexing secondary attributes.
DIt stores the actual data values of the item.
Attempts:
2 left
💡 Hint

Think about how DynamoDB organizes data physically.

📝 Syntax
advanced
2:30remaining
Correct Syntax for Adding a New Attribute to an Item

You want to add a new attribute Age with value 30 to an existing item with UserID = 101 in DynamoDB. Which UpdateItem syntax is correct?

AUpdateItem with Key={"UserID": {"N": "101"}}, UpdateExpression="SET Age = 30"
BUpdateItem with Key={"UserID": {"N": "101"}}, UpdateExpression="ADD Age :val", ExpressionAttributeValues={":val": {"N": "30"}}
CUpdateItem with Key={"UserID": {"N": "101"}}, UpdateExpression="SET Age = :val", ExpressionAttributeValues={":val": {"N": "30"}}
DUpdateItem with Key={"UserID": {"N": "101"}}, UpdateExpression="SET Age :val", ExpressionAttributeValues={":val": {"N": "30"}}
Attempts:
2 left
💡 Hint

Remember the syntax for UpdateExpression requires an equals sign and placeholders for values.

optimization
advanced
2:30remaining
Optimizing Queries with Secondary Indexes

You have a DynamoDB table with UserID as the partition key and OrderDate as a sort key. You want to efficiently query all orders placed on a specific OrderDate regardless of UserID. What is the best approach?

AQuery the table using <code>UserID</code> and filter by <code>OrderDate</code>.
BUse Scan operation with a filter on <code>OrderDate</code>.
CCreate a Local Secondary Index (LSI) with <code>OrderDate</code> as the sort key and query it.
DCreate a Global Secondary Index (GSI) with <code>OrderDate</code> as the partition key and query it.
Attempts:
2 left
💡 Hint

Think about how to query by an attribute that is not the primary key.

🔧 Debug
expert
3:00remaining
Debugging a Conditional Write Failure

You try to update an item in DynamoDB with a ConditionExpression to only update if Status is "Pending". The update fails with a ConditionalCheckFailedException. What is the most likely cause?

AThe <code>Status</code> attribute is misspelled in the condition expression.
BThe item does not exist, so the condition cannot be evaluated.
CThe <code>ConditionExpression</code> syntax is invalid and causes the failure.
DThe update operation does not support conditional expressions.
Attempts:
2 left
💡 Hint

Think about what happens if the item you want to update is missing.