首页 \ 问答 \ 我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))

我们如何根据索引更新dynamodb表(不基于primary has和range key)(how can we update dynamodb table based on index(not based on primary has and range key))

我们如何根据索引更新dynamodb表(不基于primary has和range键)。
我有一个名为key_id-index ,hash是asset_id ,range是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
});

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
});
更新时间:2023-03-21 22:03

最满意答案

你不能写入GSI。

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


You cannot write to a 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.

相关问答

更多
  • 你不能写入GSI。 您唯一的选择是首先从GSI读取,获取作为键的属性值(它们始终投影到索引上,请参阅GSI.Projections ),然后将数据写回表中。 You cannot write to a 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.Pro ...
  • 不幸的是,5个本地二级索引和5个全局二级索引是硬限制,无法扩展。 当您有更多(> 5)属性要从DynamoDB查询时,它无法有效实现。 您必须使用扫描来评估表中的所有项目,这是无效的。 您必须移动到其他数据库或使用AWS ElasticSearch索引搜索属性。 Unfortunately, 5 local secondary indexes and 5 global secondary indexes are hard limits which are not possible to extend. Wh ...
  • 我不会选择扫描,因为除非您的订单很少,否则它不具有成本效益或特别有效。 简而言之,您在全球二级索引中处于正确的轨道上。 (我假设你在谈论全球二级索引。还有本地二级索引,但我不知道这些对这个案例有多大帮助。 无论如何,我会创建一个GSI,其中OrderStatus作为Hash键,OrderId作为Range键。 但是,有几件事你需要注意。 1)写吞吐量。 请记住,具有相同OrderStatus的订单将写入GSI上的同一磁盘。 这就是Dynamo的工作方式,使用相同Hash密钥的文档会转到同一个地方。 这意味着 ...
  • 根据你的问题,我会说你如何编写你的哈希键并不重要,因为你必须使用该哈希键的确切值来查询你的表,而DynamoDB无论如何都会将它视为一个字符串。 另一件事是如果你正在编写一个范围键,那么你可能想要按如下方式编写它 john.doe_1382465533 所以你可以像这样轻松查询你的表格 hash key = whatever,range key> = john.doe_1382460000 也就是说,也许你可以通过将它直接集成到DynamoDB来摆脱你的Redis活动源,如下所示: 哈希键:用户ID 范围键 ...
  • 在DynamoDB中,您可以获得带有3个API的项目: 。 扫描 (灵活但昂贵), 。 查询 (不够灵活:你必须指定一个散列,但较便宜) 。 GetItem (通过哈希表,如果你的表有一个范围) 实现你想要的唯一方法是: 使用扫描,速度慢或昂贵。 使用另一个表(B)作为前一个(A)的索引,如: B.HASH ='VALUES'B.RANGE = userid B.lastAccesTime = lastAccesTime(带有二级索引) 现在,您必须在写入时保持该索引,但您可以将其与Query操作一起使用, ...
  • 是的,您无法使用DynamoDb获得一系列的hash_key。 但这并不意味着你坚持使用你的用例。 我们来看'日期'用例,并说你正在构建一个日志应用程序。 你很可能每天都会得到很多记录。 如果您将当天用作hash_key,则可以将完整的时间戳作为range_key。 这样,你可以将你的查询拆分成块,并得到你想要的。 当然,要获得最佳结果,您需要很好地了解这种查询。 例如,典型的范围是什么? 使用DynamoDb以及其他关键值存储,大多数情况下,大多数情况下您的数据都是在查询的基础上进行建模,而不像SQL仅在 ...
  • 它不起作用的原因是本地二级索引中的键必须与表具有相同的分区键。 因此,就您的情况而言,您的本地二级索引必须将messageId作为其HASH键,将room和userId作为RANGE键放在其各自的索引上。 并且由于你的表已经被(messageId, userId)键入(messageId, userId)所以你不需要userId本地二级索引。 (请参阅https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LSI.html )。 这种 ...
  • 动机注意:使用类似DynamoDB的云存储时,我们必须了解存储模型,因为这会直接影响您的性能,可伸缩性和财务成本。 这与使用本地数据库不同,因为您不仅支付您存储的数据,还支付您对数据执行的操作。 例如,删除记录是WRITE操作,因此如果您没有有效的清理计划(并且您的情况是时间序列数据特别需要),您将支付价格。 在处理小数据量时,您的数据模型不会显示问题,但在您需要扩展时肯定会破坏您的计划。 也就是说,诸如创建(或不创建)索引,为键定义适当属性,创建表分段等决策将使整个过程变得不同。 选择DynamoDB(或 ...
  • 给出一些假设,这是一个提案: 假设订阅ID是全球唯一的 假设您需要能够根据其订阅ID检索订阅 假设日期可以表示为数字(例如Julian Day Number) 表设计: 哈希键:SubscriptionID 其他属性CompanyID:S,StartDate:N,EndDate:N,ProductID:S 全球二级指数: ProductID-StartDate-Index:ProductID上的哈希值,StartDate上的范围 CompanyID-ProductID-index:CompanyID上的哈希 ...
  • 根据您的查询模式,您看起来正确。 如果只需要一个account_id数据,请执行Query 。 您还可以在range-key上提供KeyConditionExpression ,以仅获取在给定timestamp之后发生的事件。 如果要获取account_id列表的数据,请运行“ Scan 。 (您不能执行BatchGetItem ,因为它需要hash-key和range-key)。 As per your query patterns, you approach looks correct. If you ...

相关文章

更多

最新问答

更多
  • 在javascript中创建类以创建对象并在Java中创建类和对象之间的区别(Difference between creating a class in javascript to create an object and creating an class and object in Java)
  • Facebook API:将身份验证详细信息从Javascript SDK发送到PHP SDK(Facebook API: Send authentication detail from Javascript SDK to PHP SDK)
  • 如何停止队列动画jquery?(How can I stop queue animation jquery?)
  • 使用C#的井字游戏中的人工智能(Artificial Intelligence in Tic-Tac-Toe using C#)
  • 多少流量可以共享虚拟主机(对于Python Django站点)支持?(How Much Traffic Can Shared Web Hosting (for a Python Django site) support?)
  • 带有CIFilters的CAShapeLayer(CAShapeLayer with CIFilters)
  • 如何在Angular 2中读取JSON #text(How to read in Angular 2 the JSON #text)
  • 如何在xml中读取自闭标签的属性?(How to read self closing tag's attribute in xml?)
  • 无法使用http put将图像上传到亚马逊S3(Cannot upload image to amazon s3 using http put)
  • 文件结束无限循环(end of file infinite while-loop)
  • 在cpp的模板(template in cpp)
  • 在构建库时,clang和clang ++有什么区别?(What's the difference between clang and clang++ when building a library?)
  • ng类中的表达式(expression inside ng-class)
  • 在PHP中获取随机布尔值true / false(Get random boolean true/false in PHP)
  • 管道的高效分块用于严格的字节串(Efficient chunking of conduit for strict bytestring)
  • Python ternary_operator(如果其他标志做了其他操作,则执行其他操作)(Python ternary_operator (do-somthing if flag else do-another))
  • Sencha Touch面具发布(Sencha Touch mask ondisclosure)
  • 验证脚本上的通知[重复](Notices on validation script [duplicate])
  • 朋友功能(friend function)
  • 基于角坐标平移和变换平面几何(Translate and transform plane geometry based on corner coordinates)
  • Rails:'如果在本地运行'条件javascript标记包括(Rails: 'if running locally' conditional javascript tag include)
  • 解压文件(Unzipping files)
  • 使用ui-router以角度加载变量状态(loading in variable states with ui-router in angular)
  • 创建Azure云服务需要多长时间?(how long does it take to create an Azure Cloud Service? How to view log information?)
  • 指向整数的指针数组(Array of pointers to integers)
  • Laravel服务提供商没有看到我的包的主要类(Laravel service provider does not see the main class of my package)
  • 这个关于VSS / RSS / PSS / USS的解释是否准确?(Is this explanation about VSS/RSS/PSS/USS accurate?)
  • 在Django-Admin中通过row-id排序显示项目(Ordering the display items by row-id in Django-Admin)
  • 如何使用cythonize启用`--embed`?(How to enable `--embed` with cythonize?)
  • 用于将文本多行设置的Excel脚本(Excel script for ereasing text multiple rows)