Dynamodb查询的MultipleValidationErrors

时间:2017-07-20 15:29:54

标签: node.js amazon-dynamodb aws-lambda

我正在尝试查询表并返回要在变量中使用的结果来测试数据。下面是我检索数据的代码。 myTables中的字段是:

AlertType   min    max
----------------------
Velocity     45     100

低于错误

    var qparamsV = {
    TableName: "myTable",
    KeyConditions: "AlertType = :v",
    Key: { AlertType: AlertType},
    ExpressionAttributeValues:{
        ":v" : "Velocity",
        ":min" : min,
        ":max" : max
    }
};

    dynamo.getItem(qparamsV, function(err, Vdata) {
    if (err) {
      console.log(err); // an error occurred
      } 
    else {
      console.log(Vdata); // successful response
      alert (""+Vdata);
      }
    });

但代码会引发关于Key条件和参数的错误

MultipleValidationErrors: There were 3 validation errors: * UnexpectedParameter: Unexpected key 'KeyConditionExpression' found in params
InvalidParameterType: Expected params.Key['AlertType'] to be a structure
UnexpectedParameter: Unexpected key 'ExpressionAttributeValues' found in params at ParamValidator

2 个答案:

答案 0 :(得分:0)

假设AlertType被定义为分区键并且没有为表定义排序键,则param应如下所示: -

var qparamsV = {
    TableName: "myTable",    
    Key: { "AlertType" : {S : "Velocity"}
};

答案 1 :(得分:0)

嗯,因为我没注意到

getItem doesn't have a KeyConditionExpression

只是一个关键

Key : { AlertType:"Velocity" }