我正在学习如何与DynamoDB的.NET工作,我有一个疑问,是否有删除从现有的表中的所有项目以正确的方式?我的意思是,我不希望删除表,只是清空。 我读过有关批处理程序,但他们不帮我了。
I'm learning how to work with DynamoDB for .net and I have a doubt, Is there a correct way to delete all items from an existing table?, I mean, I don't want to delete the table, just empty it. I've read about batch process but they don't help me much.
我有这样的
private string DeleteAllFromTable()
{
string result = string.Empty;
try
{
var request = new BatchWriteItemRequest
{
RequestItems = new Dictionary<string, List<WriteRequest>>
{
{
this.Tablename, new List<WriteRequest>
{
new WriteRequest
{
DeleteRequest = new DeleteRequest
{
Key = new Dictionary<string,AttributeValue>()
{
{ "Id", new AttributeValue { S = "a" } }
}
}
}
}
}
}
};
var response = this.DynamoDBClient.BatchWriteItem(request);
}
catch (AmazonDynamoDBException e)
{
}
return result;
}
不过,当然,这只是删除匹配的值a的ID。
But of course, that only delete the id that match with the value "a".
感谢。
我会建议你只是删除该表并重新创建它。从DynamoDB 指南与表工作的的文档:
I would recommend that you just delete the table and recreate it. From the DynamoDB Guidelines for Working with Tables documentation:
...
删除整个表显著不是删除更有效 项一个接一个,这基本上加倍写吞吐量作为 你做尽可能多的删除操作是把操作。
Deleting an entire table is significantly more efficient than removing items one-by-one, which essentially doubles the write throughput as you do as many delete operations as put operations.