Deleting multiple items based on global secondary index in DynamoDB

时间:2016-10-20 20:06:54

标签: amazon-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

1 个答案:

答案 0 :(得分:15)

截至目前,您无法仅通过传递非键属性或GSI键来删除项目。

最简单的方法是查询GSI并获取primaryKey(表的哈希键)和下一个请求中的删除。

如果您想进行批量删除,可以参考this answer

希望有所帮助