DynamoDB .NET - 删除表中的所有项目 [英] DynamoDB .NET - Delete all items from a table

查看:870
本文介绍了DynamoDB .NET - 删除表中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何与DynamoDB的.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 <一href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForTables.html#GuidelinesForTables.TimeSeriesDataAccessPatterns"相对=nofollow> 指南与表工作的的文档:

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 - 删除表中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆