Amazon dynamodb DynamoDB在已经定义了分区键和排序键的情况下如何通过createdAt进行查询

Amazon dynamodb DynamoDB在已经定义了分区键和排序键的情况下如何通过createdAt进行查询,amazon-dynamodb,Amazon Dynamodb,我已经将GSI设置为author作为分区键,status作为排序键,并使用它们来查询我需要的数据。然而,我不知道如何按时间顺序对退货数据进行排序 DynamoDb工作台 ----------------------------------------------- | id | post | author | status | createdAt | ----------------------------------------------- | 1 | post1 | autho

我已经将GSI设置为author作为分区键,status作为排序键,并使用它们来查询我需要的数据。然而,我不知道如何按时间顺序对退货数据进行排序

DynamoDb工作台

-----------------------------------------------
| id | post  | author  | status  | createdAt   |
-----------------------------------------------
| 1  | post1 | author1 | publish | 2019-12-10  |
-----------------------------------------------
| 2  | post2 | author2 | draft   | 2019-12-11  |
-----------------------------------------------
| 3  | post3 | author1 | publish | 2019-12-12  |
-----------------------------------------------
以及查询

var params = {
            TableName : "TABLENAME",
            IndexName: "gsi-authorStatus",
            KeyConditionExpression: "author = :author AND status = :status",
            ExpressionAttributeValues: {
                ":author": JSON.stringify(event.bodyJSON.author),
                ":status": JSON.stringify(event.bodyJSON.status)
            }
        };

        dynamo.query(params, function (err, data) {
            if (err) {
                console.error('Error with ', err);
                context.fail(err);
            } else {
                context.succeed(data);
            }
        });

我的查询给了我作者和状态匹配的数据,但它给了我一个随机顺序的数据。可以使用
createdAt
按最新日期对返回数据进行排序?

使用createdAt作为排序键创建一个新的GSI,或者按代码而不是DB引擎对数据进行排序。@hoangdv感谢您的评论。我必须使用author和status作为分区和排序键,以便获得所需的数据。不要认为在前端对数据进行排序是可行的,因为返回的数据都是随机的,有多个分页。Author作为分区键,createdAt作为排序键,include status作为投影字段,并按status@AdrianPraja是的,这是一种方法,然后再次运行查询,直到得到一定数量的结果。然而,我试图看看是否有更好的方法来实现这一点:)除了查询所有数据并在客户端对结果进行排序之外,我看不到其他选项