weggi_swa
weggi_swa

Reputation: 330

Only retrieve specific data from a row in DynamoDB using JavaScript


Using DynamoDb and the "read" function provided here how would I go about only retrieving specific items (e.g. only firstname, lastname and city)
I would probably have to add some kind of filter, however i was not able to find anything that I could use.

This is my table structure (with bpNumber being the primary key):

Item:{
            "salutationCode": "02",
            "lastName1": "Berg",
            "firstName": "Anne",
            "street": "Am Dächle",
            "streetNumber": "22/2",
            "zipcode": "33425",
            "countryCode": "DE",
            "city": "Hausen",
            "bpNumber": 222,
            "dateOfBirth": "1955-07-01",
            "attri": [
              {
                "attri1":"nonono"
              },
              {
                "attri2": "yeayeayea"
              }
            ]

        }

and this the "read" method I'm using:

read(){
        var docClient = new AWS.DynamoDB.DocumentClient()

        var table = "businessPartnersData";

        var bpNumber = 222;

        var params = {
            TableName: table,
            Key:{
                "bpNumber": bpNumber
            }
        };

        docClient.get(params, function(err, data) {
            if (err) {
                console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
            } else {
                console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
            }
        });
  }

Thank you for you time!

Upvotes: 2

Views: 2258

Answers (1)

Peter Fennema
Peter Fennema

Reputation: 1690

You can use ProjectionExpression:

params.ProjectionExpression = "firstname, lastname, city";

This will only return these attributes in the resultset, for all items.

Upvotes: 9

Related Questions