Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS DynamoDB and Nodejs integration - how to filter between two dates?

I have a small nodejs script connected to my DynamoDB and one of my primary sort keys is datetime, which is represented in UTC.

I would like to filter the results by a certain date and time and am having issues with my Filter Expression.

var params = {
  TableName: "realtimeusers",
  ProjectionExpression: "brand, datetime, activeusers",
  KeyConditionExpression: "brand = :brand",
  FilterExpression: "datetime > :today",
  ExpressionAttributeValues: {
    ":brand": "BRAND A",
    ":today": 1464705900
  },
};

I get the error message:

 "message": "Invalid FilterExpression: Attribute name is a reserved keyword; reserved keyword: datetime",

I think I am missing something in my filter expression that I don't fully grasp.

Can some one please help?

like image 339
turtlepower Avatar asked Sep 10 '25 05:09

turtlepower


1 Answers

"datetime" is a reserved dynamo keyword. The reserved keywords are not allowed in dynamo query expressions.

The way around this is to use Expression attribute names when querying for such properties.

Reference: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeNames

like image 50
Shibashis Avatar answered Sep 12 '25 20:09

Shibashis