Firstly, DynamoDB doesn't have aggregate functions such as min
and max
like RDBMS aggregate function. However, it does have one feature to get the latest date from table. In order to use that option, the attribute should be defined as SORT
key. Also, the latest date can be found for the specific partition key only i.e. it does not apply for the whole table, just the chosen partition key.
ScanIndexForward
can be used to get the latest item for the specific partition key.
ScanIndexForward — (Boolean) Specifies the order for index traversal:
If true (default), the traversal is performed in ascending order; if
false, the traversal is performed in descending order.
In order to use the above option, the table design has to be changed.
post_id - partition key
date - sort key