gpt4 book ai didi

node.js - 从 Lambda 函数更新 dynamoDB 失败

转载 作者:太空宇宙 更新时间:2023-11-04 01:48:55 24 4
gpt4 key购买 nike

我在更新 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));
}
});

我收到以下消息:

Unable to update item. Error JSON: { "message": "The provided key element does not match the schema", "code": "ValidationException",

有什么想法为什么......?

最佳答案

AWS documentation ,您需要拆分 ExpressionAttributeNames

UpdateExpression: "SET #mapAttr.#colors = list_append(#mapAttr.#colors, :entry)",
ExpressionAttributeNames: {
"#mapAttr": "mapAttr",
"#colors": "colors"
}

关于node.js - 从 Lambda 函数更新 dynamoDB 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50422944/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com