我正在尝试学习 AWS DynamoDB,但遇到了一个看似简单却无法解决的问题。
我正在使用Dynalite本地运行在nodejs上。 错误如下;
{ [ValidationException:必须在请求中指定 KeyConditions 或 KeyConditionExpression 参数。] message: '必须在请求中指定 KeyConditions 或 KeyConditionExpression 参数。', 代码:'验证异常', 时间: 2015年12月21日星期一 17:31:47 GMT+0200 (SAST), requestId: 'RHDFVDXQTI0VZUIRJSLGRZXJFQJQYWGJOGS0B4MUDSX3H3JSVWNR', 状态代码:400, 可重试:假, 重试延迟:0 }
我的表创建如下(为简洁起见,删除了代码);
var params = {
TableName : "test",
KeySchema: [
{ AttributeName: "email", KeyType: "HASH" },
{ AttributeName: "date", KeyType: "RANGE" }
],
AttributeDefinitions: [
{ AttributeName: "email", AttributeType: "S" },
{ AttributeName: "date", AttributeType: "N" }
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
}
}
dynamodb.createTable(params, function(err, data) {
if (err) { console.log(JSON.stringify(err, null, 2)) }
} else { console.log(JSON.stringify(data, null, 2)) }
})
测试数据加载如下;
var params = {
TableName: 'test',
Item: {
"email": lowerCasedEmail,
"date": date,
"amount": amount,
}
}
dynamodbDoc.put(params, function(err, data) {
if (err){
console.log(JSON.stringify(err, null, 2))
} else {
console.log(JSON.stringify(data, null, 2))
}
})
然后失败的查询如下;
var params = {
TableName: "test",
KeyConditionExpression: "email = :testmail",
ExpressionAttributeValues: {
":testmail": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a4853517a4e5f494e14595557" rel="noreferrer noopener nofollow">[email protected]</a>"
}
}
dynamodbDoc.query(params, function(err, data) {
if (err) { console.log(err) }
else {
if (Object.keys(data).length === 0) {
console.log('Nothing found.')
} else { console.log(data) }
}
})
最佳答案
我发现了问题。 Dynalite 无法正确处理 KeyConditionExpression。
关于amazon-dynamodb - DynamoDB/Dynalite 查询未使用 NodeJS 返回查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399678/