【问题标题】:Dynamo db type conversion error ValidationException: A value provided cannot be converted into a numberDynamo db类型转换错误ValidationException:提供的值不能转换成数字
【发布时间】:2019-01-13 06:39:51
【问题描述】:

我有一个像这样的发电机数据库查询。我执行将数据添加到两个不同的表,这个问题是第一个问题的延续。 Using batchWriteItem in dynamodb

  var createuser = {
        "RequestItems": {
          "users": [
            {
              "PutRequest": {
                Item: {
                  "userid": { "N": "usrid" },
                  "role": { "S": 'candidate' },
                  "password": { "S": vucrypt.encryptpass(pass) }
                }
              }
            }
          ],
          "candidate": [
            {
              "PutRequest": {
                Item: {
                  "fname": {
                    "S": req.body.fname
                  },
                  "lname": {
                    "S": req.body.lname
                  },
                  "location": {
                    "S": req.body.location
                  },
                  "phone": {
                    "S": req.body.phone
                  },
                  "ccode": {
                    "S": req.body.ccode
                  },
                  "grad": {
                    "S": req.body.grad
                  },
                  "pgrad": {
                    "S": req.body.pgrad
                  },
                  "ograd": {
                    "S": req.body.ograd
                  },
                  "experience": {
                    "N": "10"
                  },
                  "linkedin": {
                    "S": req.body.linkedin
                  },
                  "terms": {
                    "S": tandc
                  }
                }
              }
            }
          ]
        }
      }

当我执行此代码时,我收到这样的错误。

ValidationException: A value provided cannot be converted into a number

我试过这个。

var exps = Number(exp);

但是,这个错误仍然存​​在,我该怎么办?有什么想法吗?

我的代码是这样的。

  dynamodb.batchWriteItem(createuser, function(err, regdata) {
    vulog.debug(regdata);
    if (err || !regdata || regdata.Responses.UnprocessedItems) {
      vulog.warn('ddb: error in checking corp user details1 \n' + err);
      res.send(400, 'Unable to register at present, please try later');
      return;
    }
    vulog.debug('Candidate added successful');

    res.send(200, 'Success! Your account has been created.\n Check your email for further instructions.');
  });

【问题讨论】:

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


    【解决方案1】:

    所有值都必须是字符串:

    例如:

    "fname": {
        "S": req.body.fname
    }
    

    req.body.fname 必须是字符串

    所以添加

    req.body.fname + ""
    

    req.body.fname.toString();

    【讨论】:

    • 这不起作用我不断收到此错误ValidationException: A value provided cannot be converted into a number
    • 你的错误在这里 "userid": { "N": "usrid" } ,从用户ID中删除引号。并将用户 ID 转换为字符串:"userid": { "N": usrid + "" }
    • 还是没有希望:(
    • 但是错误改了ValidationException: One or more parameter values were invalid: An AttributeValue may not contain an empty string
    • ok,所以根据报错,检查一下是否没有空字符串,能不能做console.log(createuser)并显示结果
    猜你喜欢
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    相关资源
    最近更新 更多