【发布时间】:2018-10-29 13:57:02
【问题描述】:
我在更新 DynamoDB 条目时遇到问题。
数据库看起来像这样
{
"userId":"amzn1.ask.account.XYZ",
"mapAttr":{
"name":"John",
"colors":[
"yellow",
"white"
]
}
}
我想使用以下代码更新颜色列表:
var docClient = new AWS.DynamoDB.DocumentClient({ apiVersion: "2012-08-10" });
var params = {
TableName: "myTable",
Key: {
userId: userId
},
UpdateExpression: "SET #mapAttr = list_append(#mapAttr, :entry)",
ExpressionAttributeNames: { "#mapAttr": "mapAttr.colors" },
ExpressionAttributeValues: {
":entry": ["blue"]
},
ReturnValues: "UPDATED_NEW"
};
docClient.update(params, function(err, data) {
if (err) {
console.error(
"Unable to update item. Error JSON:",
JSON.stringify(err, null, 2)
);
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
}
});
我收到以下消息:
无法更新项目。错误 JSON:{“消息”:“提供的密钥 元素与架构不匹配", "code": "ValidationException",
任何想法为什么...?
【问题讨论】:
-
尝试“SET #mapAttr.#colors”并将“#colors”属性添加到 ExpressionAttributeNames。
-
肯定不是重复的。在上述链接中,有人在更新单个项目列时遇到问题,而我需要一个解决方案来更新列 mapAttr 中称为颜色的列表类型属性,该属性单独是一个属性对象。
-
找到解决方案了吗?
-
很遗憾没有。
标签: node.js aws-lambda amazon-dynamodb alexa-skills-kit