我正在学习如何使用 DynamoDB for .net,我有一个疑问,是否有从现有表中删除所有项目的正确方法?我的意思是,我不想删除表,只是清空它。 我读过有关批处理的信息,但它们对我帮助不大。
我有这个
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。
谢谢。
最佳答案
我建议您只删除表并重新创建它。来自 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.
关于c# - DynamoDB .NET - 从表中删除所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30733640/