我想根据特定的主键值从 Node.js 访问 Amazon Data 服务器的数据。数据以以下形式提供:
{
"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}}};
有什么想法吗?任何帮助将不胜感激。
最佳答案
如果范围键存在于“Key”中,您还必须为参数传递范围键
例子 应该是
Key:{'thePrimaryKey':{ "S": 'primaryKey' }, 'theRangeKey': {'S': 'rangeKey'} }
希望这对您有所帮助!
关于javascript - 如何从 node.js 访问 dynamodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22039780/