Sabreena
Sabreena

Reputation: 649

How to sort all items according to registration date in dynamoose

Summary: How to sort all items according to registration date. When I tried it gives me no output, My code is shown below

Code sample:

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);
    })
}

Schema

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 }

Environment:

Upvotes: 1

Views: 1591

Answers (1)

Charlie Fish
Charlie Fish

Reputation: 20496

Few issues here.

  1. You have to use Query.exec() to pass in your callback function instead of passing it into the ascending function.
  2. You must use Query.eq() for your hash key.
  3. You must use the index property on your schema, and use the rangeKey property to sort using that. See this line and this line in the tests for more details on how to do a descending query.

Upvotes: 1

Related Questions