Wednesday, 3 May 2017

DynamoDB return specific data items to a variable

I am trying to show some results of the query to DynamoDB on frontend but I am not able to return the specific data items I need to show on the front end using Node.js.

Here is my code:

function getuserdetails(username) {
    var docClient = new AWS1.DynamoDB.DocumentClient();
    var table = "USER";
    var value1={};


    var params = {
        TableName: table,
        Key: {
            "UserID": username  
        }
    }


    docClient.get(params, function (err, data) {
        if (err) {
            console.error("Unable to read item. Error JSON:", data);
            value1=data;

        } else
        {

            value1["Name"]=data.Item.Name;
            value1["Rating"]=data.Item.Rating;
            value1["ProfilePic"]=data.Item.Profile_Picture;
            value1["Room_Interested"]=data.Item.Room_Interested;
            value1["Preferences"]=data.Item.Preferences;
            value1["User_ID"]=data.Item.UserID;




        }
    });

I want that whenever I call x=getuserdetails(2) , I should be returned value1(with names and other feilds)structure but i am always returned {} which I guess is the same variable I used for declaration. How can I approach this?



via user3930213

No comments:

Post a Comment