Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting multiple records in dynamo db

can we delete multiple records in dynamo db only through range key?

I'm trying to do like this sql statement

delete from employee where employee_name='gopal';

so here the records with employee name gopal should get deleted

can we achieve same like this sql query in dynamo db?

like image 675
lokanathjack Avatar asked Sep 21 '17 04:09

lokanathjack


People also ask

How do I delete multiple records in DynamoDB?

With the DynamoDB API, you use the DeleteItem action to delete data from a table, one item at a time. You must specify the item's primary key values. In addition to DeleteItem , Amazon DynamoDB supports a BatchWriteItem action for deleting multiple items at the same time.

How do you clean up DynamoDB?

Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/ . In the navigation pane, choose Tables. Choose the Features table. From the Actions menu, choose Delete Table.

How do I truncate a DynamoDB table?

Go to your DynamoDB table dashboard. You can navigate there from DynamoDB -> Tables -> YourTable -> Dashboard. Click on the truncate button to truncate your table. You'll see a confirmation dialog asking you to type TRUNCATE to confirm.


2 Answers

You would have to do a BatchWriteItem to delete your items. From the documentation:

BatchWriteItem performs put and delete

like image 85
Deividi Silva Avatar answered Oct 29 '22 06:10

Deividi Silva


Please Check This query it's working with multiple data

const params = {TableName: "test"};

docClient.scan(params, (error, result) => {
        if (error) { console.log(error,"error scan"); }

        result.Items.forEach(function(item) {          
            docClient.delete({Key:{mainID: item.id},TableName:"test"}, (error) => {
                if (error) {
                    console.log("Delete fail");
                }
                console.log("Delete  Success");
            });
        });

});    
like image 42
Dhaval Mojidra Avatar answered Oct 29 '22 06:10

Dhaval Mojidra