如何根据动态列从dynamodb中获取排序数据

How to get sorted data from dynamodb based on dynamic column

我是 Dynamodb 的新手, 我有 table 名字是 "user",其中有两列,一列是 "time",另一列是 "cost"。 我想根据列名获取排序的数据, 假设我将输入参数作为 "time" 以升序提供前 50 条记录,如果我将输入参数作为 "cost" 提供,则前 50 条记录。

我已经尝试过类似的方法,但这不起作用。

{
    TableName: "User",
    Limit: 50,
    ScanIndexForward: false,
    ExclusiveStartKey: (params.lastEvaluatedKey)? {tripId: {S: String(params.lastEvaluatedKey)}}: null,
    KeyConditionExpression   : 'cost > :costValue',
    ExpressionAttributeValues : {
       ':costValue': '1'
    }
}

在此先致谢。

不幸的是,Dynamodb 没有对 table 中的所有属性进行排序的功能。您只能使用 ScanIndexForward is true/false.

按排序键对项目进行排序

如果您想按排序键以外的属性对项目进行排序,则必须在客户端进行(即 Dynamodb 没有此功能)。