我们如何根据索引更新dynamodb表(不基于primary has和range键)

时间:2015-10-01 11:17:52

标签: node.js amazon-dynamodb

如何根据索引更新dynamodb表(不基于primary has和range键) 我有一个名称key_id-index创建的索引 哈希值为asset_id,范围为hit_id。 我想根据key_id-index更新表格,因为在更新时我不会知道这些内容。

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
});

1 个答案:

答案 0 :(得分:4)

您无法写入GSI。

您唯一的选择是先从G​​SI读取,获取您的密钥属性值(它们始终投影到索引上,请参阅GSI.Projections),然后将数据写回表中。

相关问题