dynobase-icon
Dynobase

DynamoDB: Delete Multiple Items in Javascript (Guide w/ Code Examples)

Rafal Wilinski

Provided by Rafal Wilinski

To delete multiple items from a DynamoDB table using the JavaScript SDK, you can use the batchWritemethod. This method allows you to delete multiple items in a single call, which can be more efficient than making multiple individual delete calls.

const AWS = require('aws-sdk'); const dynamoDb = new AWS.DynamoDB.DocumentClient(); const tableName = 'myTable'; const itemsToDelete = [ { DeleteRequest: { Key: { id: 'item1', }, }, }, { DeleteRequest: { Key: { id: 'item2', }, }, }, // ... add more items to delete here ]; const params = { RequestItems: { [tableName]: itemsToDelete, }, }; dynamoDb.batchWrite(params, (err, data) => { if (err) { console.error(err); } else { console.log(data); } });

Better DynamoDB experience.

First 7 days are on us. No strings attached.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2024 Dynobase
+
Better DynamoDB Experience.
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.