Reputation: 13
I am trying to get max value from id item. I am using ScanIndexForward:false which returns desc order of id values which is not working as expected now its giving the same insertion order from the table.
Please see my code below and please suggest if any changes required.
var params1 = {
TableName: "Test",
Limit:3,
ProjectionExpression: 'id',
ScanIndexForward:false,
};
docClient.scan(params1, function (err, data) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("Query succeeded."+JSON.stringify(data, null, 2));
}
});
Thanks,
Upvotes: 1
Views: 3383
Reputation: 14849
You are performing a scan, which does not have a parameter called ScanIndexForward
. The Query operation does have a parameter called ScanIndexForward
.
The only way you can order results in a DynamoDB query is by the sort key attribute - results are ordered by default. If you want to order by any other attribute, or order scan results, you have to do it in your client application.
Upvotes: 2