Let’s take a look at how to query top 5 scores from AWS DynamoDB, let say we have some top scores table and want to get top 5 performers for the specific country. What we also need is not to waste the network resources, that’s why we will specify what exact fields we need to fetch from server – with help of projectionExpression.
Moreover let’s take a look at how to deal with the following error:
com.amazon.coral.validate#ValidationException”,”message”:”Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: name”
it could be solved by adding reserved words to the expressionAttributeNames, e.g. instead of
queryExpression.projectionExpression = "userId,challenge,country,name,total"
where name and total are reserved words let’s do the following
queryExpression.expressionAttributeNames = [ "#n": "name", "#t": "total", ] queryExpression.projectionExpression = "userId,challenge,country,#n,#t"
That approach will eliminate the ValidationException – reserved keyword; reserved keyword error.
Here’s the whole method
Continue reading “AWS DynamoDB query top 5 scores for country”