首页 文章

使用AWS低级API将null AttributeValue传递到DynamoDb

提问于
浏览
1

我正在尝试使用C#低级API更新DynamoDB表中的项目here

以下是我实现这一目标的尝试:

var response = DynamoClientProvider.Current.UpdateItem(new UpdateItemRequest
{
    TableName = "MyTable",
    Key = {{"TableId", new AttributeValue {S = "12345"}}},
    ExpressionAttributeNames =
    {
        {"#T","Timestamp"},
        {"#D","Data"}
        {"#K","MyKey"}
    },
    ExpressionAttributeValues =
    {
        {":Timestamp", new AttributeValue("2016-2-3 00:00:00.000")},
        {":Data", new AttributeValue("some data")}
        {":MyKey", new AttributeValue("some other data")}
    },
    UpdateExpression = "SET #D = :Data, #T = :Timestamp, #K = :MyKey",
    ConditionExpression = "attribute_not_exists (Data)",
    ReturnValues = ReturnValue.ALL_OLD
});

此代码工作得很好,但是当 MyKey 是空字符串时会出现问题 . 当它为空时,我收到以下错误:

Amazon.DynamoDBv2.AmazonDynamoDBException:ExpressionAttributeValues包含无效值:提供的AttributeValue为空,必须包含key的唯一支持的数据类型之一:MyKey

因此,我尝试传入一个null AttributeValue ,以便在这种情况下通过将其设置为以下内容来删除该属性:

new AttributeValue{NULL = true}

但是,这会将值设置为 True 的字符串文字

1 回答

  • 1

    我不确定DynamoDB的类型是否可以为空 .

    如果需要删除属性,请使用'SET #D =:Data,#T =:Timestamp REMOVE #K'

相关问题