[英]Boto3 updating multiple values
in the boto3 documentation updating an item is described by this example:在 boto3 文档中更新一个项目是由这个例子描述的:
table.update_item(
Key={
'username': 'janedoe',
'last_name': 'Doe'
},
UpdateExpression='SET age = :val1',
ExpressionAttributeValues={
':val1': 26
}
)
But what am i supposed to do, if i want to update several values of the item.但是,如果我想更新该项目的多个值,我该怎么办。 I couldn't find any information on this.
我找不到这方面的任何信息。 Can anybody help?
有人可以帮忙吗? Thank you!
谢谢!
EDIT:编辑:
Ok, it seems to work like this, can anybody confirm wether this is the right way.好的,它似乎是这样工作的,任何人都可以确认这是正确的方法。 Just to be sure i'm not doing anything totally wrong here.
只是为了确保我在这里没有做任何完全错误的事情。
table.update_item(
Key={
'id': item['id']
},
UpdateExpression='SET value1 = :val1, value2 = :val2',
ExpressionAttributeValues={
':val1': someValue1,
':val2': someValue2
}
)
Thanks!谢谢!
For others finding this, theres a library you can use to help with the weird boto3 stuff like ExpressionAttributeValues
.对于发现此问题的其他人,您可以使用一个库来帮助处理奇怪的 boto3 内容,例如
ExpressionAttributeValues
。 This way you can make normal developer/human calls.通过这种方式,您可以进行正常的开发人员/人工调用。
https://github.com/rayepps/dynamof https://github.com/rayepps/dynamof
db(update(
table_name='users',
key={ 'id': item['id'] },
attributes={
'age': 26,
'name': 'Carl'
}))
disclaimer: I wrote it免责声明:我写的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.