【问题标题】:How can I add data to a multivalued attribute in DynamoDB using boto?如何使用 boto 将数据添加到 DynamoDB 中的多值属性?
【发布时间】:2014-06-10 18:07:24
【问题描述】:

在我的表中,假设我存储了一些这样的数据:

Item(Table('test'), data={'id': '123', 'content': 'test', 'list': set([1,2,3,4])}).save()

这有一个多值属性“列表”。我想在表中搜索 id=123,如果它存在,更新“list”属性,将另一个列表附加到它上面,比如 [5,6]

一些搜索让我找到了this stackoverflow answer,它指向UpdateItem 操作,但是我找不到如何使用ADD 操作的示例。

谁能提供我如何做到这一点的示例?我是 python 和 DynamoDB 的初学者。

【问题讨论】:

    标签: python amazon-web-services boto amazon-dynamodb


    【解决方案1】:
    from boto.dynamodb2.table import Table
    table = Table('users')
    
    item = table.get_item(id=123)
    for i in #your_list_to_append#:
        item['list'].append(i)
    item.save(overwrite=True)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      • 2021-04-18
      • 1970-01-01
      • 2018-10-09
      • 1970-01-01
      • 2019-04-14
      相关资源
      最近更新 更多