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# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01