DynamoDB: Query Date Range (Guide w/ Code Examples)
Provided by Rafal Wilinski
To query a date range using the AWS JavaScript SDK, you can use the query
operation.
var AWS = require('aws-sdk'); var dynamo = new AWS.DynamoDB({region: 'us-west-2'}); var params = { TableName: 'my-table', KeyConditionExpression: '#timestamp between :start_date and :end_date', ExpressionAttributeNames: { '#timestamp': 'timestamp' }, ExpressionAttributeValues: { ':start_date': {N: '1577836800'}, // January 1, 2020 ':end_date': {N: '1609459200'} // December 31, 2020 } }; dynamo.query(params, function(err, data) { if (err) { console.error(err); } else { console.log(data); } });
In this example, the KeyConditionExpression
is set to check if the timestamp
attribute is between :start_date
and :end_date
. The ExpressionAttributeNames
and ExpressionAttributeValues
are used to map the attribute names and values used in the expression to the actual attribute names and values in the table.
Similar Code Examples
- DynamoDB: Batch Get
- DynamoDB: Query Greater Than
- DynamoDB: Get Last Inserted Item
- DynamoDB Get in Typescript
- DynamoDB: Get List Of Items
- DynamoDB: Delete
- DynamoDB: Attribute Not Null
- DynamoDB: Not Begins With
- DynamoDB: GetItem
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: Get Query
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: Get Unique Values
- DynamoDB: Get Multiple Items
- DynamoDB: Query Count
Login to the AWS Console less. Use Dynobase.
First 7 days are on us. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase