DynamoDB: Increment Counter (Guide w/ Code Examples)

Provided by Rafal Wilinski
To increment a counter in DynamoDB using the JavaScript SDK, you can use the update method and provide an update expression that uses the ADD function to increase the counter's value. Here is an example of how to increment a counter named "counter" by 1:
var params = { TableName: "myTable", Key: { "id": { N: "123" } }, UpdateExpression: "ADD counter :val", ExpressionAttributeValues: { ":val": { N: "1" } }, ReturnValues: "UPDATED_NEW" }; dynamodb.update(params, function(err, data) { if (err) { console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2)); } else { console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2)); } });
Similar Code Examples
- DynamoDB: Bulk Insert
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: BatchGetItem
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: GetItem
- DynamoDB Get in Typescript
- DynamoDB: Get Last 10 Records
- DynamoDB: Get All Items
- DynamoDB: Not Begins With
- DynamoDB: Create if Not Exists
- DynamoDB: Delete Multiple Items in Javascript
- DynamoDB: Query JSON
- DynamoDB: Like
- DynamoDB: Query Greater Than
- DynamoDB: Query Group By
Dynobase is a Professional GUI Client for DynamoDB
Try 7-day free trial. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2026 Dynobase