Consider a DynamoDB table with a partition key UserID and a sort key Timestamp. You run this query to get all items for UserID = 'user123':
QueryRequest request = new QueryRequest()
.withTableName("UserActivity")
.withKeyConditionExpression("UserID = :uid")
.withExpressionAttributeValues(Map.of(":uid", new AttributeValue().withS("user123")))
.withScanIndexForward(true);What order will the items be returned in?
Look at the withScanIndexForward(true) parameter.
Setting ScanIndexForward to true returns results in ascending order by the sort key.
You want to get the latest activity first for a user in a DynamoDB table with UserID as partition key and Timestamp as sort key. Which parameter should you set in the query?
Think about reversing the order of the sort key.
Setting ScanIndexForward to false returns results in descending order by the sort key.
DynamoDB queries allow ordering results by the sort key only. Why is it not possible to order by other attributes?
Think about how DynamoDB stores and indexes data physically.
DynamoDB stores items sorted by partition key and sort key only. Ordering by other attributes would require scanning all items, which is inefficient and not supported in Query.
Which option contains a syntax error in setting the query to return results in descending order?
QueryRequest request = new QueryRequest()
.withTableName("UserActivity")
.withKeyConditionExpression("UserID = :uid")
.withExpressionAttributeValues(Map.of(":uid", new AttributeValue().withS("user123")))
.withScanIndexForward(???);Check the expected data type for withScanIndexForward.
The withScanIndexForward method expects a boolean value, not a string.
You want to get the 5 most recent activities for a user from a DynamoDB table with UserID as partition key and Timestamp as sort key. Which approach is best?
Think about how to limit data read and get results in desired order.
Querying with ScanIndexForward set to false returns items in descending order by sort key. Using Limit(5) restricts results to 5 items, making it efficient.