问题描述
我一直在尝试找出如何更新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",
}
}
})
推荐答案
您似乎正在尝试使用表达式,在这种情况下,您的 UpdateExpression
不正确. ExpressionAttributeNames
和ExpressionAttributeValues
都用于占位符替换在您的表情中.
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中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!