Reputation: 15064
I have a DynamoDB and some items there have a date field. The date field is a string of the format {YYYY-MM-DD}. What should I have to write that the DB will retrieve all items which date field is between a start date and an end date?
This is my code:
function searchFile(from_date, until_date) {
AWS.config = new AWS.Config({accessKeyId: '***', secretAccessKey: '***', region: '***'});
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = {
"TableName" : '***',
FilterExpression: "Date_ = :date",
ExpressionAttributeValues: {
// What should I write here?
},
}
dynamodb.scan(params, function(err,data) {
if (err) {
console.log(err);
}
console.log(data);
})
}
Upvotes: 4
Views: 3682
Reputation: 39226
The DynamoDB stores dates as String. You can use BETWEEN
operator to get the range of dates.
createdate - is the attribute name
FilterExpression: "createdate BETWEEN :date1 and :date2",
ExpressionAttributeValues: {
":date1": "2010-05-05",
":date2": "2011-10-04",
}
Date S (string type). The Date values are stored as ISO-8601 formatted strings.
BETWEEN : Greater than or equal to the first value, and less than or equal to the second value.
Upvotes: 8