0

I am trying to add more email address to the list. The architecture and the example in Dynamo DB

ID: STRING
DEP: MAP
    Contacts: MAP
        EMAIL: LIST
Version: Number
    

{
 “ID”: "1234567888",
 "Dep": {
            "Contacts": {
                   "Email": [
                            "test@test.com”
                            ]
                   }
           },
 "Version": 34
}

I tried but it just updates the value but don't add the new one. (if you can also help me with if the value does not exist than only add would be nice but not mandatory)

$eav = $marshaler->marshalItem([":email" => [$email]]);
$params = ['TableName' => "xxx", 'ID' => $key, 
        'UpdateExpression' => 'SET Dep.Contacts.Email = :email',
    'ExpressionAttributeValues' => $eav, 'ReturnValues' => 'UPDATED_NEW'];
                        
$result = $dynamodb->updateItem($params);
cpat431
  • 5
  • 1

1 Answers1

0

You should list_append to add an element to a list. CLI example below:

--update-expression "SET #ri = list_append(#ri, :vals)" 

You can see this in the documentation here:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html#Expressions.UpdateExpressions.SET.AddingListElements

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31