Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting multiple items based on global secondary index in DynamoDB

I have an existing table which has two fields - primary key and a global secondary index:

----------------------------
primary key | attributeA(GSI)
----------------------------
1           | id1
2           | id1
3           | id2
4           | id2
5           | id1

Since having the attributeA as a global secondary index, can I delete all items by specifying a value for the global secondary index? i.e I want to delete all records with the attributeA being id1 - Is this possible in Dynamo?

Dynamo provides documentation about deleting the index itself, but not specifically if we can use the GSI to delete multiple items

like image 234
chrisrhyno2003 Avatar asked Oct 20 '16 20:10

chrisrhyno2003


People also ask

How do I delete multiple items 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 I delete a global secondary index?

If you no longer need a global secondary index, you can delete it using the UpdateTable operation. You can delete only one global secondary index per UpdateTable operation. While the global secondary index is being deleted, there is no effect on any read or write activity in the parent table.

How many global secondary Indexs are there in DynamoDB?

Each table in DynamoDB can have up to 20 global secondary indexes (default quota) and 5 local secondary indexes. For more information about the differences between global secondary indexes and local secondary indexes, see Improving data access with secondary indexes.

How many global secondary indexes are allowed per table?

For maximum query flexibility, you can create up to 20 global secondary indexes (default quota) and up to 5 local secondary indexes per table.


1 Answers

As of now, you cannot delete an item just by passing Non-key attributes or GSI keys.

The simplest way to do this is to Query GSI and get primaryKey(Hash key of the table) and Delete in next request.

You can refer this answer if you want to do batchDeletion.

Hope that helps

like image 51
Harshal Bulsara Avatar answered Oct 13 '22 00:10

Harshal Bulsara