1
我想學習AWS DynamoDB並遇到一個看似簡單的問題,我找不出來。DynamoDB/Dynalite查詢不返回查詢與nodejs
我在本地使用在nodejs上運行的Dynalite。 錯誤如下;
{[ValidationException:無論是KeyConditions或KeyConditionExpression參數必須在請求中指定的] 消息:「要麼KeyConditions或KeyConditionExpression參數必須在請求中指定。」, 代碼:「ValidationException」, 時間:星期一2015年12月21日17時31分47秒GMT + 0200(SAST), 的requestId: 'RHDFVDXQTI0VZUIRJSLGRZXJFQJQYWGJOGS0B4MUDSX3H3JSVWNR', 的StatusCode:400,可重試 :假, 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": "[email protected]"
}
}
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) }
}
})
對於這個問題的狀態,我正在關注[這個問題](https://github.com/mhart/dynalite/issues/24)。 –