knu2xs knu2xs - 20 days ago 7
Javascript Question

With AWS DocumentClient less than on secondary index query - "Query key condition not supported"

The function below, it should be simple, right? This is what I thought as well. Still, for the life of me, I cannot figure out why I keep getting an error informing me of a, "

ValidationException
," with an error informing me, "
Query key condition not supported
."

const getUpdated = (refreshDatetime, callback) => {

refreshDatetime = parseInt(refreshDatetime);

docClient.query({
TableName: 'aw-reach',
IndexName: 'updateDatetime-index',
KeyConditionExpression: ':refreshDatetime < updateDatetime',
ExpressionAttributeValues: {
':refreshDatetime': refreshDatetime,
}
}, (error, data) => {
if (error) callback(error, null);
callback(null, data.Items);
});
};


Just to make sure I am not doing anything else incredibly stupid (a distinct possibility as well), here is the snippet I am using to test.

const refreshDatetime = Date.parse('01 Jan 2015');
getUpdated(refreshDatetime, (error, response) => {
console.log(JSON.stringify(response));
});


Insight and ideas are welcomed and greatly appreciated as writing code, even this little code, definitely is not my strongest talent!

Update: To add additional detail, my hash key is
reachId
, and my partition key associated with my secondary index is
updateDatetime
.

enter image description here

Answer

Dynamodb does not allow to use any other condition except "=" on Hash/partition key.

You can optionally use other expressions for Range/sort key but not for Hash key.

refer: Documentation link

Another post with similar problem

Hope that helps.