我正在使用lambda函数中的onScan从表中检索数据。我想根据时间戳对它们进行排序。请为此提供建议
var params = {
TableName: "LogEvents",
FilterExpression: "#Environment = :env",
ExpressionAttributeNames: {
"#Environment": "Environment",
}
};
答案 0 :(得分:0)
希望以下示例对您有帮助。
var params = {
TableName: "Table",
IndexName: "DataID-Created-index",
KeyConditionExpression: "DataID = :v_ID AND
Created > :v_created",
ExpressionAttributeValues: {":v_ID": {S: "some_id"},
":v_created": {N: "timestamp"}
},
ProjectionExpression: "ID, DataID, Created, Data"
};
ddb.query(params, function(err, data) {
if (err)
console.log(err);
else {
data.Items.sort(function(a, b) {
return parseFloat(a.Created.N) -
parseFloat(b.Created.N);
});
// More code here
}
});