1

我正在尝试使用Dynamoose获取 table 的最新行

我阅读了query().ascending()and query.descending(),但据我了解,我需要查询整个表,这要求 hashkey 为空。scan()不支持排序。

就像是:

MyModel
.scan()                // 1. scan the whole table
.descending('my_date') // 2. sort by descending by a date
.limit(100)            // 3. limit the results to 100
.exec(function(error, data) {
    // return error or data
});

有谁知道如何获得最新的行?

提前致谢!

4

1 回答 1

2

DynamoDB 或 Dynamoose API 都不支持获取最新结果。您可能需要在客户端执行此操作(即编写自定义代码以实现此结果)。

DynamoDB API:-

该属性需要定义为SORT 键,以对数据进行升序或降序排序。

甚至Dynamoose API也不会按所有属性对数据进行排序。它仅按排序键对数据进行排序。

  • query.descending() - 按表的排序键属性以降序对数据进行排序
于 2017-06-21T14:03:07.357 回答