Is it possible to ORDER results with query or scan in DynamoDB?

前端 未结 6 771
长发绾君心
长发绾君心 2020-12-04 16:42

Is it possible to ORDER results with Query or Scan API in DynamoDB?

I need to know if DynamoDB has something like [ORDER BY \'field\'] from SQL queries?

Tha

6条回答
  •  佛祖请我去吃肉
    2020-12-04 16:52

    You can use the sort-key and apply the ScanIndexForward parameter in a query to sort in either ascending or descending order. Here I limit items returned to 1.

    var params = {
        TableName: 'Events',
        KeyConditionExpression: 'Organizer = :organizer',
        Limit: 1,
        ScanIndexForward: false,    // true = ascending, false = descending
        ExpressionAttributeValues: {
            ':organizer': organizer
        }
    };
    
    docClient.query(params, function(err, data) {
        if (err) {
            console.log(JSON.stringify(err, null, 2));
        } else {
            console.log(JSON.stringify(data, null, 2));
        }
    });
    

提交回复
热议问题