a) scan and sort the items on your own
b) or create a global secondary index with just one hash key and dump all your items into that hashkey. It is not recommended because this creates a hot partition in GSI.
c) or design your schema to avoid having to sort items globally.
1 回答
对于只有一个范围键的第一个问题,您可以使用本地二级索引 . 您将普通属性指定为LSI的范围键,DynamoDB将通过比较该属性对您的行(使用相同的哈希键)进行排序 . 所以LSI基本上给你“额外的rangeKey” . 您最多可以创建5个LSI .
有关查询LSI的示例,请参阅here和here . 您可以像处理常规表一样处理索引 . 您可以对索引进行查询和扫描(但不能放置) .
关于关于全局排序行而不是使用相同的hashkey排序项的第二个问题,我不认为DynamoDB支持开箱即用的这个功能 . 你不得不