0
0
DynamoDBquery~10 mins

Query by partition key in DynamoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to query items by partition key in DynamoDB.

DynamoDB
response = table.query(KeyConditionExpression=Key('[1]').eq('123'))
Drag options to blanks, or click blank then click option'
AEmail
BSortKey
CTimestamp
DUserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using the sort key instead of the partition key in the query condition.
Using an attribute name that does not exist in the table schema.
2fill in blank
medium

Complete the code to query items with a specific partition key value using boto3.

DynamoDB
response = table.query(KeyConditionExpression=Key('UserId').eq([1]))
Drag options to blanks, or click blank then click option'
A"User123"
B'123'
C123
DUser123
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the key value without quotes causing a syntax error.
Using variable names instead of string literals.
3fill in blank
hard

Fix the error in the query code to correctly use the partition key.

DynamoDB
response = table.query(KeyConditionExpression=Key('[1]').eq('abc'))
Drag options to blanks, or click blank then click option'
AUserId
BSortKey
CPartitionKey
DTimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like 'PartitionKey' which is not the actual attribute name.
Confusing partition key with sort key attribute names.
4fill in blank
hard

Fill both blanks to query items by partition key and sort key condition.

DynamoDB
response = table.query(KeyConditionExpression=Key('[1]').eq('user1') & Key('[2]').begins_with('2023'))
Drag options to blanks, or click blank then click option'
AUserId
BTimestamp
CSortKey
DEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping partition key and sort key names.
Using attribute names not defined in the table.
5fill in blank
hard

Fill all three blanks to query items by partition key and filter results by an attribute.

DynamoDB
response = table.query(KeyConditionExpression=Key('[1]').eq('user42'), FilterExpression=Attr('[2]').[3]('active'))
Drag options to blanks, or click blank then click option'
AUserId
BStatus
Ceq
Dbegins_with
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'begins_with' instead of 'eq' in the filter expression.
Using wrong attribute names for partition key or filter.