gpt4 book ai didi

python - 如何删除 boto3 DynamoDB key ?

转载 作者:太空宇宙 更新时间:2023-11-03 15:06:35 25 4
gpt4 key购买 nike

这是我的 DynamoDB JSON

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

我需要从数据库中删除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
}
)

我遇到以下错误..

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

最佳答案

这绝对不是the correct syntax 。如果您想从 target_followed_users 集中删除特定项目,则可以使用以下语法:

UpdateExpression='删除 followed_back_users :followed_back_users'

其中 followed_back_user 是要从集合中删除的值列表。

如果您想从 DynamoDB 记录中完全删除 followed_back_users 属性,则可以使用以下语法:

UpdateExpression='删除 follow_back_users'

关于python - 如何删除 boto3 DynamoDB key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44602536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com