1

I have a table in Dynamo db called Settings the unique keys is email and has an attribute called display_names this is type Map and has the following structure{'123-456': "any name", '789-123': 'another name'}

I'm trying to delete the name at with the attribute '123-456' with the following params

TableName: 'Settings',
        Key: {
            email: '[email protected]',
        },
        UpdateExpression: 'DELETE display_names :p',
        ExpressionAttributeValues: '{":p" : {"S": 123-456}}'
    };

But when I run the code I get the following error ExpressionAttributeValues contains invalid key: Syntax error; key: \"11\"",

I hope you can help me, thank you in advance!

1
  • I realized that the problem is that the Map key is a uuid, and when I try to access using square brackets but I get an error Syntax error; token: \"\"\", near: \"[\"96\"", so I'm wondering what would be the correct form to access the value Commented Mar 20, 2020 at 15:13

1 Answer 1

1

You can use below UpdateExpression to remove a key from the map.

const keyToDelete = '123-456';
const params = {
  TableName: 'Settings',
  Key: {
    email: '[email protected]',
  },
  UpdateExpression: `REMOVE #parent.#key`, // Here. Note: use `` instead of '',
  ExpressionAttributeNames: {  
    "#parent": 'display_names',
    "#key": keyToDelete
  },  
  ReturnValues: 'ALL_NEW'
};
Sign up to request clarification or add additional context in comments.

3 Comments

I have tried that before but I get the following error "Unable to update produect: ValidationException: Invalid UpdateExpression: Syntax error; token: \"123\", near: \".123-\"",
I updated the answer, use [] to access attribute. Let’s correct double quotes , I edited by iPhone then the characters are not correctly
It seems that is not a valid syntax for Dynamo "Unable to update produect: ValidationException: Invalid UpdateExpression: Syntax error; token: \"\"\", near: \"[\"123\"",

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.