我想從特定主鍵值的Node.js訪問Amazon數據服務器的數據。該數據是可用的形式:如何從node.js訪問dynamo數據庫
{
"Count": 9862,
"Items": [
{
"Admin": {
"S": "false"
},
"UserId": {
"S": "e9633477-978e-4956-ab34-cc4b8bbe4adf"
},
"Age": {
"N": "76.24807963806055"
},
"Promoted": {
"S": "true"
},
"UserName": {
"S": "e9633477"
},
"Registered": {
"S": "true"
}
},
{
"Admin": {
"S": "false"
},
"UserId": {
"S": "acf3eff7-36d6-4c3f-81dd-76f3a8071bcf"
},
"Age": {
"N": "64.79224276370684"
},
"Promoted": {
"S": "true"
},
"UserName": {
"S": "acf3eff7"
},
"Registered": {
"S": "true"
}
},
每次當我製作的代碼請求:
app.get('/Mydetails/:tablename/:id', function(req, res){
console.log('Table is ' + req.params.tablename);
var element = {TableName: req.params.tablename, Key:{UserID:{"S": '"'+req.params.id+'"' }}};
console.log('Id is "' + req.params.id + '"');
dynamodb.getItem(element, function(err, data){
if(err){
console.log('Error occurred: '+err);
}else{
console.log('succeed');
res.json(data);
}
});
那麼它提供了以下錯誤:
**ValidationException: The provided key element does not match the schema.**
不過我曾嘗試這也是 -
var element = {TableName: req.params.tablename, Key:{UserId:{"S": +req.params.id}}};
任何想法?任何幫助將不勝感激。
你爲什麼在這裏使用+號+ req.params.id?這會將id更改爲一個數字(在第二種情況下),您的模式顯示userId是一個字符串。 –