DynamoDB .NET - Delete all items from a table(DynamoDB .NET - 从表中删除所有项目)
问题描述
我正在学习如何使用 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 - 从表中删除所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:DynamoDB .NET - 从表中删除所有项目


基础教程推荐
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01