I'm using DynamoDB to store records for a web application.
Each record has a uuid (partition key) and a unix timestamp (sort key). How can I get all records sorted by newest timestamp?
Using scan is expensive, and using submitting a partition key is apparently necessary using a Query
I get the following error with the code I have tried already:
Query condition missed key schema element: uuid
My service:
serverCallChats() {
return new Promise(async (resolve, reject) => {
const _dynamoDB = new AWS.DynamoDB.DocumentClient();
const daysBack = (days) => {
const date = new Date();
date.setDate(date.getDate() - days);
return date.getTime();
};
const params = {
TableName: 'chat-channel',
KeyConditionExpression: '#sortKeyName < :days',
ExpressionAttributeNames: {
'#sortKeyName': 'timestamp'
},
ExpressionAttributeValues: {
':days': daysBack(7)
}
};