[英]how make update query in Aws DynamoDB using nodeJS
I need to update one item of DynamoDB, here is my Code.我需要更新 DynamoDB 的一项,这是我的代码。
const Aws = require('aws-sdk');
const endPoint= 'http://dynamodb.us-east-2.amazonaws.com';
const IAm_user_Key=process.env.IAM_USER_KEY;
const IAm_user_Secret=process.env.IAM_USER_SECRET;
Aws.config.update({ accessKeyId:IAm_user_Key,secretAccessKey:IAm_user_Secret,region:'us-east-2',endpoint:endPoint });
var docClient = new Aws.DynamoDB.DocumentClient();
var table = "cards";
var params={
TableName:table,
key:{ "cardid":clientData.data.cardid},
AttributeValue:{"data":clientData.data}
}
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
})
I am facing issues while running this code here my error.我在此处运行此代码时遇到问题我的错误。
Unable to update item.无法更新项目。 Error JSON: {
错误 JSON:{
"message": "Missing required key 'Key' in params", "code": "MissingRequiredParameter", "message": "在参数中缺少必需的键 'Key'", "code": "MissingRequiredParameter",
"time": "2019-07-20T07:47:06.490Z" } “时间”:“2019-07-20T07:47:06.490Z” }
But you can see I have Key object in params but still struggling for this.但是您可以看到我在 params 中有 Key 对象,但仍在为此苦苦挣扎。
我阅读文档太多次了,但有一个愚蠢的错误,我发现这只是参数中的拼写错误“key”应该是大写的“Key”K,这是有效的。
var params={
TableName:table,
Key:{ "cardid":clientData.data.cardid, 'name': req.body.name},
AttributeValue:{"data":clientData.data}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.