简体   繁体   中英

How to delete boto3 DynamoDB key?

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"

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM