首页 > 解决方案 > 如何在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 }

环境:

标签: node.jssortingamazon-dynamodbdynamoose

解决方案


这里很少有问题。

  1. 您必须使用Query.exec()传递回调函数而不是将其传递给升序函数。
  2. 您必须使用Query.eq()您的哈希键。
  3. 您必须index在架构上使用该属性,并使用该rangeKey属性进行排序。有关如何进行降序查询的更多详细信息,请参阅测试中的这一行这一行。

推荐阅读