我们如何基于索引(而不是基于主has和范围键)更新dynamodb表 [英] how can we update dynamodb table based on index(not based on primary has and range key)

查看:52
本文介绍了我们如何基于索引(而不是基于主has和范围键)更新dynamodb表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何基于索引(而不是基于主has和range键)更新dynamodb表.
我有一个按名称 key_id-index 创建的索引哈希为 asset_id ,范围为 hit_id .我想基于 key_id-index 更新表,因为在更新时我不知道这些.

how can we update dynamodb table based on index(not based on primary has and range key).
I have a index created by name key_id-index and hash is asset_id and range is hit_id. i want to update the table based on key_id-index because i wouldn't know those while updating.

var paramsu = {
  TableName: 'asset',
  //IndexName: 'key_id-index',
  Key: { // The primary key of the item (a map of attribute name to AttributeValue)

    asset_id: { S: 'a' },
    hit_id: { S: 'h' }
    // more attributes...
  },
  AttributeUpdates: { // The attributes to update (map of attribute name to AttributeValueUpdate)

    key_id: {
      Action: 'PUT', // PUT (replace)
                     // ADD (adds to number or set)
                     // DELETE (delete attribute or remove from set)
      Value: { S: 'updated1' }
    }
    // more attribute updates: ...
  },

  ReturnValues: 'NONE', // optional (NONE | ALL_OLD | UPDATED_OLD | ALL_NEW | UPDATED_NEW)
  ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES)
  ReturnItemCollectionMetrics: 'NONE' // optional (NONE | SIZE)
};
db.updateItem(paramsu, function(err, data) {
  if (err) console.log(err); // an error occurred
  else console.log(data); // successful response
});

推荐答案

您无法写入GSI.

您唯一的选择是首先从GSI中读取,获取作为您键的属性值(它们总是投影到索引上,请参见

Your only option is to first read from the GSI, get the attribute values that are are your keys (they are always projected onto the index, see GSI.Projections), and then write your data back to the table.

这篇关于我们如何基于索引(而不是基于主has和范围键)更新dynamodb表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆