0
0
DynamoDBquery~20 mins

Query by partition key in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Partition Key Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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 Items
A[{ OrderID: '1001', Customer: 'Bob', Amount: 100 }]
B[{ OrderID: '1002', Customer: 'Alice', Amount: 250 }]
C[]
DSyntaxError: Missing ExpressionAttributeNames
Attempts:
2 left
💡 Hint
Remember, querying by partition key returns all items with that key.
📝 Syntax
intermediate
2: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'
  }
};
AAll syntax is correct
BExpressionAttributeValues key should be ':UserID' not ':uid'
CKeyConditionExpression should be 'UserID == :uid'
DMissing comma after TableName property
Attempts:
2 left
💡 Hint
Check the commas between object properties carefully.
optimization
advanced
2: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?
AKeyConditionExpression: 'UserID = :uid AND Timestamp > :time', ExpressionAttributeValues: { ':uid': 'user42', ':time': '2023-01-01' }
BKeyConditionExpression: 'UserID = :uid', FilterExpression: 'Timestamp > :time', ExpressionAttributeValues: { ':uid': 'user42', ':time': '2023-01-01' }
CFilterExpression: 'UserID = :uid AND Timestamp > :time', ExpressionAttributeValues: { ':uid': 'user42', ':time': '2023-01-01' }
DScan with FilterExpression: 'UserID = :uid AND Timestamp > :time', ExpressionAttributeValues: { ':uid': 'user42', ':time': '2023-01-01' }
Attempts:
2 left
💡 Hint
Use KeyConditionExpression to filter by partition and sort keys efficiently.
🔧 Debug
advanced
2: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'
  }
};
ATableName is incorrect
BMissing FilterExpression to narrow results
CPartition key value case mismatch: 'P123' vs 'p123'
DKeyConditionExpression syntax error
Attempts:
2 left
💡 Hint
DynamoDB partition keys are case sensitive.
🧠 Conceptual
expert
2: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?
AQuerying by partition key is not allowed without a sort key condition
BQuerying by partition key requires specifying a sort key condition
CQuerying by partition key returns only the latest item by OrderDate
DQuerying by partition key returns all items for that CustomerID, regardless of OrderDate
Attempts:
2 left
💡 Hint
Think about how DynamoDB organizes items with composite keys.