DynamoDB: Query KeyConditionExpression (Guide w/ Code Examples)
![Rafal Wilinski](https://pbs.twimg.com/profile_images/1390706809548197895/SVCKpLNE_400x400.png)
Provided by Rafal Wilinski
The KeyConditionExpression
parameter is used to specify the key condition for query operations. It should be a string that follows the syntax of a condition expression, and it should be specified using the attribute name and value placeholders (Attribute_name = :value).
The ExpressionAttributeValues
parameter is used to provide the values for the placeholders in the KeyConditionExpression
. The values should be passed in an object where the keys are the placeholder names.
Here's an example of how you might use the query
method to retrieve items from a DynamoDB table where the partition key is userId
and the sort key is timestamp
:
const AWS = require('aws-sdk'); const dynamodb = new AWS.DynamoDB.DocumentClient(); const params = { TableName: 'myTable', KeyConditionExpression: 'userId = :userId and timestamp >= :startTimestamp', ExpressionAttributeValues: { ':userId': '123', ':startTimestamp': 1560934400 } }; dynamodb.query(params, (err, data) => { if (err) { console.log(err); } else { console.log(data); } });
Similar Code Examples
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Get Random Item
- DynamoDB: BatchGetItem
- DynamoDB: Create if Not Exists
- DynamoDB: Get Last Inserted Item
- DynamoDB: Bulk Insert
- DynamoDB: GetItem
- DynamoDB: Get Unique Values
- DynamoDB: Query Group By
- DynamoDB: Delete Table
- DynamoDB: Query Ends With
- DynamoDB: Get List Of Items
- DynamoDB: Query Count
- DynamoDB: Not Begins With
- DynamoDB: Get Query
Dynobase is a Professional GUI Client for DynamoDB
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase