node.js - 我们如何根据索引更新 dynamodb 表(而不是基于主要 has 和范围键)

标签 node.js amazon-dynamodb

我们如何根据索引更新 dynamodb 表(而不是基于主 has 和范围键)。
我有一个由名称 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
});

最佳答案

您不能写入 GSI。

您唯一的选择是首先从 GSI 读取,获取作为您的键的属性值(它们总是投影到索引上,请参阅 GSI.Projections),然后将您的数据写回表中。

关于node.js - 我们如何根据索引更新 dynamodb 表(而不是基于主要 has 和范围键),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886247/

相关文章:

javascript - 传递刚刚创建的参数

javascript - Node.js 获取字符串中所有出现的子字符串

amazon-web-services - 具有 StaticTableSchema 的嵌套 bean 和来自 AWS Java SDK 2.x 的增强型 DynamoDB 客户端

php - 存储和检索数百万个 JSON 编码的事件(PHP/数据库)

javascript - 为 armv7 编译 node.js v0.10.31 时出错

javascript - 使用正则表达式替代 HTML 解析

node.js - npm 安装失败 - make 失败

go - 使用结构更新值

amazon-web-services - 笔记应用程序的 DynamoDB 分区键选择

amazon-web-services - 如何修复错误 "DynamoDB returns GSI range key not specified errors"?