20
votes

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

1

1 Answers

32
votes

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