我正在 DynamoDB 中尝试批量写入,但失败了。
TableName - td_notes_learn
PK user_id - String
SK datetime - Number
我的尝试:
const AWS = require("aws-sdk");
AWS.config.update({ region: "us-east-1" });
const docClient = new AWS.DynamoDB.DocumentClient();
docClient.batchWrite(
{
RequestItems: {
td_notes_learn: [
{
DeleteRequest: {
Key: {
user_id: "D",
datetime: 5
}
},
PutRequest: {
Item: {
user_id: "G",
datetime: 5,
content: "HELLO WORLD"
}
}
}
]
}
},
(err, data) => {
if (err) {
console.log("Error found" + err);
} else {
console.log(data);
}
}
);
异常(exception) :
Error foundValidationException: Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes
此外,在相同的代码中,如果我运行
DeleterRequest
和 PutRequest
通过评论另一个单独请求,代码工作正常,只有当我一起运行时才会发生错误。请指导我。
最佳答案
看起来所有请求都需要是一个单独的 json 对象,而我的代码中的问题是所有请求都在一个 json 对象中。下面是工作代码。
docClient.batchWrite(
{
RequestItems: {
td_notes_learn: [
{
DeleteRequest: {
Key: {
user_id: "D",
datetime: 5
}
}
}, // WAS MISSING
{ // WAS MISSING
PutRequest: {
Item: {
user_id: "G",
datetime: 5,
content: "HELLO WORLD"
}
}
} // WAS MISSING
]
}
},
(err, data) => {
if (err) {
console.log("Error found" + err);
} else {
console.log(data);
}
}
);
关于node.js - DynamoDB 异常 - 提供的 AttributeValue 设置了不止一种数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60695821/