简体   繁体   English

在DynamoDB中,如何使用Java将元素附加到列表字段

[英]In DynamoDB how do I append an element to a list field using Java

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) 我在DynamoDB中有一条记录,其中包含一个名为imageData的字段,该字段是项目列表,每个项目都是字典(包含键值对的映射)

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? 有没有更好的办法?

这是在DynamoDB中追加到列表属性的好方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM