2

I have a record in DynamoDB with an field named imageData, this field is a list of items, each item is a dictionary (map containing key value pairs)

How can I append new items to the list in the following record

 { "ssid": "abcd", "imageData": []}

I tried

Table table = dynamoDB.getTable("my_table");

HashMap imageData = new HashMap();
    imageData.put("imageKey", "xyz.jpg" );
    imageData.put("imageUploadTimestamp", "2016-12-12 23:59:59");

ValueMap map = new ValueMap().withList(":img", Arrays.asList(imageData));

UpdateItemSpec updateItemSpec = new UpdateItemSpec()
            .withPrimaryKey(SSID, ssid)
            .withUpdateExpression("set imageData = list_append(imageData, :img )")
            .withValueMap(map);

UpdateItemOutcome result = table.updateItem(updateItemSpec);

Is this the right way? is there a better way?

Alexander Patrikalakis
  • 5,054
  • 1
  • 30
  • 48
Vijay Kumar
  • 2,439
  • 2
  • 32
  • 51

1 Answers1

1

This is a good approach to appending to a list attribute in DynamoDB.

Alexander Patrikalakis
  • 5,054
  • 1
  • 30
  • 48