3

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.

1
  • Why are you using the + sign here +req.params.id? That would change the id to a number (in your second case) which your schema shows userId to be a string. Commented May 8, 2017 at 18:13

3 Answers 3

1

You have to also pass the range key if it exists in the 'Key', for the parameters

example it should be

Key:{'thePrimaryKey':{ "S": 'primaryKey' }, 'theRangeKey': {'S': 'rangeKey'} }

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

It appears you are sending a variable named params which I don't see where you populate it.

You should be sending element: dynamodb.getItem(element, callback)

1 Comment

yeah ,I have used dynamodb.getItem(element, function(err, data) this line as well but nothing happens,means same result.
0

Looks like there is a typo (case difference) in your UserID (vs UserId). - Upper case D. Give a try with this change.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.