DynamoDB: Delete Multiple Items in Javascript (Guide w/ Code Examples)
![Rafal Wilinski](https://pbs.twimg.com/profile_images/1390706809548197895/SVCKpLNE_400x400.png)
Provided by Rafal Wilinski
To delete multiple items from a DynamoDB table using the JavaScript SDK, you can use the batchWrite
method. 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); } });
Similar Code Examples
- DynamoDB: Delete
- DynamoDB: Not Between
- DynamoDB: Create if Not Exists
- DynamoDB BatchWriteItem in Typescript
- DynamoDB: GetItem
- DynamoDB: Query Ends With
- DynamoDB: Get Last Inserted Item
- DynamoDB: Query Global Secondary Index in Nodejs
- DynamoDB: Delete All Items With Partition Key
- DynamoDB: Get By ID
- DynamoDB: Query Count
- DynamoDB: Get Table
- DynamoDB: Get All Items
- DynamoDB: Bulk Insert
- DynamoDB: Query Greater Than
Tired of AWS Console? Try Dynobase.
First 7 days are on us. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2024 Dynobase