【问题标题】:How to add new attributes to a existing row without change existing attributes for Dynamodb Table如何在不更改 Dynamodb 表的现有属性的情况下向现有行添加新属性
【发布时间】:2017-01-20 09:55:26
【问题描述】:

我在 DynamoDB 中有一个表,其中包含以下属性和相应的值。

  1. 属性1
  2. 属性2
  3. 属性3

现在我想将attribute5、attribute6、attribute7添加到表中的同一行而不更改现有的属性值。

我尝试了下面的代码并删除了旧的属性值。

try:
   my_table.put_item(Item={'key': keyvalue,'attribute5': 0, 'attribute6':0, 'attribute7':0})
except Exception as e:
   logger.error("at method add_source_defaults %s", e)

我怎样才能完成这项任务。

【问题讨论】:

    标签: python amazon-dynamodb boto boto3


    【解决方案1】:

    你需要用你的表哈希键来更新你的项目,然后像这样更新它。

    from boto.dynamodb2.table import Table
    my_table = Table('tablename')
    
    item = my_table.get_item(key ='keyvalue')
    
    item['attribute5'] = 0
    
    item['attribute6'] = 1
    
    item['attribute7'] = 2
    
    item.save()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 2018-05-09
      • 2019-08-22
      • 2018-02-27
      • 2018-12-23
      • 2017-11-27
      • 1970-01-01
      相关资源
      最近更新 更多