我正在尝试查询表并返回要在变量中使用的结果来测试数据。下面是我检索数据的代码。 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
答案 0 :(得分:0)
假设AlertType
被定义为分区键并且没有为表定义排序键,则param应如下所示: -
var qparamsV = {
TableName: "myTable",
Key: { "AlertType" : {S : "Velocity"}
};
答案 1 :(得分:0)
getItem doesn't have a KeyConditionExpression
只是一个关键
Key : { AlertType:"Velocity" }