我正在尝试学习亚马逊网络服务的DynamoDB,遇到了一个看起来很简单的问题,我搞不懂。
我在本地使用在nodejs上运行的Dynalite。错误如下;
{ ValidationException:必须在请求中指定KeyConditions或KeyConditionExpression参数。消息:‘必须在请求中指定KeyConditions或KeyConditionExpression参数。’,代码:'ValidationException',时间: Mon Dec 21 2015 17:31:47 GMT+0200 (SAST),requestId: false statusCode: 400,retryable: false,retryDelay: 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": "rik@test.com"
}
}
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) }
}
})发布于 2015-12-26 19:31:42
我找到问题了。Dynalite不能正确处理KeyConditionExpression。
https://stackoverflow.com/questions/34399678
复制相似问题