how to update map list in dynamo db

2019-08-25 03:22发布

问题:

I have a item which looks like

  { Item: { Users=[], Paid=0} }

This is my base structure when I start. Now I want to add user information to the Users list

{ Item: { Users=[{name:pqr,school:mno}, {name:xyz, school:abc}], Paid=0} }

I am trying something like

        Item outcome2 = table.getItem(spec);
        final Map<String, Object> val1 = new HashMap<String, Object>();
        val1.put("name", "oliver");
        val1.put("school", "rit");
        UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("year", year)
            .withUpdateExpression("set UsersDetails = list_append(:prepend_value, UsersDetails)")
            .withValueMap(new ValueMap().withMap(":prepend_value", val1))
            .withReturnValues(ReturnValue.UPDATED_NEW);

Another fail try

UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("year", year)
            .withUpdateExpression("add #a = list_append(#a, :val1)")
            .withNameMap(new NameMap().with("#a", "UsersDetails"))
            .withValueMap(
                    new ValueMap().with(":val1", val1))
            .withReturnValues(ReturnValue.UPDATED_NEW);

I want to add/update a json structure to the list.