I want access the Data of Amazon Data server from Node.js on specific primary key value. The Data is Available in the form:
{
"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"
}
},
Everytime when I am Making Request with the code:
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);
}
});
then it gives the following error:
**ValidationException: The provided key element does not match the schema.**
However I have tried this also-
var element = {TableName: req.params.tablename, Key:{UserId:{"S": +req.params.id}}};
Any Idea? Any help will be Appreciated.
+req.params.id? That would change the id to a number (in your second case) which your schema shows userId to be a string.