1

摘要:如何根据注册日期对所有项目进行排序。当我尝试它没有输出时,我的代码如下所示

代码示例:

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
4

1 回答 1

1

这里很少有问题。

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