Atomic在C#中使用DynamoDB增加计数器字段

Ida*_*ter 3 c# amazon-dynamodb

我想知道如何将Amazon DynamoDB表中的字段增加1.根据我的理解,我需要使用UpdateItemwith Action ADD但我无法做到.

我需要一个例子,如何在C#中做到这一点.让我们假设一个带有idhash 的表和一个count在创建行时设置为0的计数器.

注意:在使用旧版本完成此问题 ID的亚马逊页面的引用,我需要使用V2的解决方案.

谢谢.

Pav*_*nov 5

您需要构建的请求如下所示:

var request = new UpdateItemRequest
{
    TableName = "Table",
    Key = new Dictionary<string, AttributeValue>
    {
        { "id", new AttributeValue { N = "5" } }
    },
    AttributeUpdates = new Dictionary<string, AttributeValueUpdate>()
    {
        {
            "count",
            new AttributeValueUpdate { Action = "ADD", Value = new AttributeValue { N = "1" } }
        },
    },
};
Run Code Online (Sandbox Code Playgroud)