简体   繁体   English

如何删除boto3 DynamoDB密钥?

[英]How to delete boto3 DynamoDB key?

This is my DynamoDB JSON 这是我的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... 我需要从数据库中删除target_followed_users ,所以我很累...

# 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; botocore.exceptions.ClientError:调用UpdateItem操作时发生错误(ValidationException):无效的UpdateExpression:语法错误; token: "=", near: "followed_back_users = :followed_back_users" 令牌:“ =”,附近:“ 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: 如果要从target_followed_users集合中删除特定项目,则可以使用以下语法:

UpdateExpression='DELETE followed_back_users :followed_back_users'

where followed_back_user would be the list of values to delete from the set. 其中followed_back_user是要从集合中删除的值的列表。

If you want to to completely remove the followed_back_users attribute from the DynamoDB record, then you would use the following syntax: 如果要从DynamoDB记录中完全删除followed_back_users属性,则可以使用以下语法:

UpdateExpression='REMOVE followed_back_users'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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