无法更新 DynamoDB 中的项目 [英] can't update item in DynamoDB

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

问题描述

我一直试图弄清楚如何更新 dynamoDB 中的项目,但没有任何成功.

I have been trying to figure out how to update an item in dynamoDB but have not had any success.

我知道如何添加和删除项目但不更新.

I know how to add and item and remove an item but not update.

这是我的代码:

dynamoDB.updateItem({
    "TableName": "mytable",
    "Key": {
        "thing_ID": {"S": "0000"}
    },
    "UpdateExpression": "SET",
    "ExpressionAttributeNames": {
        "SessionID": ""
    },
    "ExpressionAttributeValues": {
        "SessionID": {
            "S": "maybe this works",
        }
    }
})

推荐答案

您似乎正在尝试使用 Expression,在这种情况下,您的 UpdateExpression 不正确.ExpressionAttributeNamesExpressionAttributeValues 都用于 占位符替换在你的表达式中.

It looks like you are trying to update an item by using an Expression, and in this case, your UpdateExpression is incorrect. Both the ExpressionAttributeNames and ExpressionAttributeValues are used for placeholder substitution in your expression.

如果您想为项目设置属性,我认为您的代码看起来像这样:

I think your code would look something like this, if you want to set an attribute for an item:

dynamoDB.updateItem({  
    "TableName" : "exampleTable",
    "Key" : {
        "hashAttributeName" : {
            "S" : "thing_ID"
        }
    },
    "UpdateExpression" : "SET #attrName =:attrValue",
    "ExpressionAttributeNames" : {
        "#attrName" : "SessionID"
    },
    "ExpressionAttributeValues" : {
        ":attrValue" : {
            "S" : "maybe this works"
        }
    }
});

这将更新如下所示的项目:

This will update an item that looks like this:

{  
    "Item":{  
        "hashAttributeName":"thing_ID"
    }
}

到这里:

{  
    "Item":{  
        "hashAttributeName" : "thing_ID",
        "SessionID" : "maybe this works"
    }
}

这篇关于无法更新 DynamoDB 中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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