node.js - DynamoDB 异常 - 提供的 AttributeValue 设置了不止一种数据类型

标签 node.js amazon-web-services amazon-dynamodb

我正在 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



此外,在相同的代码中,如果我运行 DeleterRequestPutRequest通过评论另一个单独请求,代码工作正常,只有当我一起运行时才会发生错误。请指导我。

最佳答案

看起来所有请求都需要是一个单独的 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/

相关文章:

mysql - Node.js 安全

amazon-web-services - 开发用于浏览和上传到 S3 的自定义 SPA

amazon-web-services - DSE Spark 独立集群启动应用程序 'remote Akka client disassociated' 错误

arrays - DynamoDB : UpdateExpression for updating arrays

javascript - 在 puppeteer/JavaScript 中重试 page.goto、page.waitForNavigation 等的最佳实践

node.js - NodeJS 事件是否会传递到其父函数?

node.js - Angular 4 - 检测 http 请求的连接问题

mysql - Amazon RDS CPU 峰值

python - 使用过滤器表达式从 dynamo db 查询返回固定数量的项目

nosql - 不进行大量扫描时的表扫描与 GSI