node.js - 如何在dynamoose中根据注册日期对所有项目进行排序
问题描述
摘要:如何根据注册日期对所有项目进行排序。当我尝试它没有输出时,我的代码如下所示
代码示例:
abcdschema.statics.fetchall = function fetchall(cb) {
var id_temp='abcd';
this.query('id').contains(id_temp).where('regDate').ascending(function(err,res){
console.log(err,res);
})
}
架构
id: {
type: String,
required: true,
hashKey: true
},
name: {
type: String,
required: true,
rangeKey: true
},
regDate: { type: Date, required: true, default: Date.now },
activeFlag: { type: Boolean, default: true }
环境:
- 操作系统:ubuntu
- 操作系统版本:14.04
- Node.js 版本(node -v):9.3.0
- NPM 版本:(npm -v):5.5.1
- Dynamoose 版本:0.8.7
解决方案
这里很少有问题。
- 您必须使用
Query.exec()
传递回调函数而不是将其传递给升序函数。 - 您必须使用
Query.eq()
您的哈希键。 - 您必须
index
在架构上使用该属性,并使用该rangeKey
属性进行排序。有关如何进行降序查询的更多详细信息,请参阅测试中的这一行和这一行。
推荐阅读
- token - 我不能使用 WebJS 对 ERC20 令牌使用 Openzeppelin transferFrom 方法
- mysql - 创建一个组合两个表的视图,从一个表中优先考虑行
- django - /admin/password_change/ 和 /accounts/password_change/ 使用相同的模板,除非我手动指定一些 urlpatterns
- ios - AWS 放大 | iOS Swift 用户身份验证
- docker - 将 docker 镜像迁移到自定义注册表
- java - Fortify Eclipse 与 Fortify Audit Workbench 不匹配
- java - 是否可以修改 @WithMockUser 以获取和 Id?
- reactjs - 如何通过 React 钩子中的道具传递信息来显示引导模式?
- java - 从 webm 和其他文件中获取幻数
- python - xhtml2pdf 使用边框半径 css