1
votes

This is my DynamoDB JSON

{
  "follow_count": 3,
  "followed_back_count": 4,
  "followed_back_users": [
    32432
  ],
  "login": "login1",
  "target": "target1",
  "target_followed_users": [
    234232342,
    453453434,
    241413422
  ]
}

I need to delete the target_followed_users from the db so I tired this...

# Update for followed_back_users
table.update_item(
    Key={
        'login': login,
        'target': target,
    },
    UpdateExpression='DELETE followed_back_users = :followed_back_users',
    ExpressionAttributeValues={
        ':followed_back_users': db_followed_back_users
    }
)

I got below error..

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the UpdateItem operation: Invalid UpdateExpression: Syntax error; token: "=", near: "followed_back_users = :followed_back_users"

1

1 Answers

1
votes

That's definitely not the correct syntax. If you want to delete a specific item from your target_followed_users set then you would use the syntax:

UpdateExpression='DELETE followed_back_users :followed_back_users'

where followed_back_user would be the list of values to delete from the set.

If you want to to completely remove the followed_back_users attribute from the DynamoDB record, then you would use the following syntax:

UpdateExpression='REMOVE followed_back_users'