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": [
                            "[email protected]”
                            ]
                   }
           },
 "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);
1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.