amazon-dynamodb - 已定义分区键和排序键时,DynamoDB如何通过createdAt查询
问题描述
我已经将 GSI 设置为作者作为分区键和状态作为排序键,并使用它们来查询我需要的数据。但是,我不知道按时间顺序对返回数据进行排序。
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
最新的返回数据顺序吗?
解决方案
推荐阅读
- sql - 如何在 SQL 中不使用 DISTINCT 删除重复值?
- google-calendar-api - 谷歌日历 webhook 测试
- java - 从在 Azure Active Directory 中完成身份验证的主体访问电子邮件 ID
- r - 在 Sparklyr 中使用 ml_fpgrowth 选择支持和置信度值
- shell - Shell脚本是数值控制
- authentication - 将外部登录令牌从 Identity Server 流向客户端应用程序
- node.js - “SecurityError: 无法构造 'WebSocket': 可能无法从通过 HTTPS 加载的页面启动不安全的 WebSocket 连接。”
- firebase - 在哪里以及如何正确使用 Firebase 中的 enablePersistence() 方法以离线使用 Web 应用程序?
- java - 用于特定任务的单独文件中用于 Spark 的额外记录器
- ios - 使用未声明的标识符“self”。当我尝试在函数中使用 [self presentViewController]