A DynamoDB table uses OrderID (partition key) and NumberOfItemsPurchased (sort key), both as Number types. Query results are currently returned sorted by NumberOfItemsPurchased in ascending order. The developer wants the query results sorted in descending order by NumberOfItemsPurchased. How can this be accomplished?
Choose an answer
Tap an option to check your answer.
Correct answer: Set the Query operation parameter ScanIndexForward to false..
Why this is the answer
The ScanIndexForward parameter in a DynamoDB Query operation controls the order of results. By default, it's set to true, returning results in ascending order of the sort key. Setting ScanIndexForward to false reverses this, returning results in descending order of the sort key. This directly addresses the requirement to sort by NumberOfItemsPurchased in descending order. Creating an LSI wouldn't change the sort order for the base table's query. Renaming the sort key is not a valid DynamoDB operation to alter sort order. KeyConditionExpression is used to specify conditions for the primary key or index key, not to control the sort order of the results.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed