问题描述
我正在学习如何使用 DynamoDB for .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.
这篇关于DynamoDB .NET - 从表中删除所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!