Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to query items in ascending order by sort key.
DynamoDB
response = table.query(
KeyConditionExpression=Key('UserId').eq('123'),
ScanIndexForward=[1]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True for ascending order.
Using string values like 'ASC' which are invalid.
✗ Incorrect
Setting ScanIndexForward=True returns results in ascending order by the sort key.
2fill in blank
mediumComplete the code to query items in descending order by sort key.
DynamoDB
response = table.query(
KeyConditionExpression=Key('UserId').eq('456'),
ScanIndexForward=[1]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using True instead of False for descending order.
Using string values like 'DESC' which are invalid.
✗ Incorrect
Setting ScanIndexForward=False returns results in descending order by the sort key.
3fill in blank
hardFix the error in the query to order results ascending by sort key.
DynamoDB
response = table.query(
KeyConditionExpression=Key('UserId').eq('789'),
ScanIndexForward=[1]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string 'True' or 'False' instead of boolean True or False.
Confusing ascending and descending values.
✗ Incorrect
The ScanIndexForward parameter must be a boolean, not a string.
4fill in blank
hardFill both blanks to query items for UserId '101' in descending order.
DynamoDB
response = table.query(
KeyConditionExpression=Key([1]).eq([2]),
ScanIndexForward=False
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the sort key name instead of the partition key.
Using a wrong user ID value.
✗ Incorrect
The partition key is 'UserId' and the value to match is '101'.
5fill in blank
hardFill all three blanks to query items for UserId '202' in ascending order with correct key and value.
DynamoDB
response = table.query(
KeyConditionExpression=Key([1]).eq([2]),
ScanIndexForward=[3]
) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True for ascending order.
Using wrong key or value strings.
✗ Incorrect
Use 'UserId' as the key, '202' as the value, and True for ascending order.