dynobase-icon
Dynobase

DynamoDB: Increment Counter (Guide w/ Code Examples)

Rafal Wilinski

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)); } });

Login to the AWS Console less. Use Dynobase.

First 7 days are on us. No strings attached.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
/
Affiliates & Influencers
© 2024 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.