0
0
DynamoDBquery~10 mins

Query with sort key conditions 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 with a specific partition key.

DynamoDB
response = table.query(KeyConditionExpression=Key('UserId').eq([1]))
Drag options to blanks, or click blank then click option'
A'user123'
Buser123
CUserId
DKey('UserId')
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the partition key value.
Using the key name instead of the key value.
2fill in blank
medium

Complete the code to query items where the sort key is greater than a given value.

DynamoDB
response = table.query(KeyConditionExpression=Key('UserId').eq('user123') & Key('Timestamp').[1](1000))
Drag options to blanks, or click blank then click option'
Alt
Bgt
Ceq
Dbegins_with
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' which means less than.
Using 'eq' which means equal to.
3fill in blank
hard

Fix the error in the code to query items where the sort key begins with a prefix.

DynamoDB
response = table.query(KeyConditionExpression=Key('UserId').eq('user123') & Key('Timestamp').[1]('2023-'))
Drag options to blanks, or click blank then click option'
Acontains
Bstartswith
Cbegins_with
Dstarts
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startswith' which is not valid in DynamoDB.
Using 'contains' which checks substring anywhere.
4fill in blank
hard

Fill both blanks to query items with partition key 'user123' and sort key less than 5000.

DynamoDB
response = table.query(KeyConditionExpression=Key([1]).eq([2]) & Key('Timestamp').lt(5000))
Drag options to blanks, or click blank then click option'
A'UserId'
B'user123'
C'Timestamp'
D'5000'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the sort key name in the first blank.
Not putting quotes around the strings.
5fill in blank
hard

Fill all three blanks to query items where partition key is 'user123', sort key begins with '2023-', and sort key is greater than 1000.

DynamoDB
response = table.query(KeyConditionExpression=Key([1]).eq([2]) & Key([3]).begins_with('2023-') & Key('Timestamp').gt(1000))
Drag options to blanks, or click blank then click option'
A'UserId'
B'user123'
C'Timestamp'
D'Date'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up partition key and sort key names.
Not using quotes around string values.