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 - 从表中删除所有项目
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
