Reads and cost · Lesson 6 of 20
Read the latest first
A sorted timestamp makes 'the most recent' a direction, not a sort in your code.
Why
Every reading from a fridge shares that fridge's partition key, and the sort key is an ISO-8601 timestamp. A fixed-width ISO timestamp sorts lexically in time order, so the newest reading is simply the last one in the partition.
That makes 'the latest' a direction. ScanIndexForward false walks the partition newest-first, and a Limit stops it early. Run all three: direction and limit are request fields, not a second query and a sort back in your own code.
Sort by a fixed-width timestamp and the latest N is a descending Query with a Limit, never a scan-then-sort.
ScanIndexForward false reads the partition newest-first, and Limit 1 stops at the top row.
Run an operation to see the raw engine response.