简体   繁体   English

DynamoDB在对象数组(nodejs)中更新

[英]DynamoDB update inside an array of objects (nodejs)

I noticed that DynamoDB can add and remove items from an array but how do you search for an specific item inside an object if you want to update that one specifically? 我注意到DynamoDB可以在数组中添加和删除项目,但是如果要具体更新该对象,如何在对象中搜索特定项目? For example: In MongoDB you can search for someitem.$.subitem and update that specific item. 例如:在MongoDB中,您可以搜索someitem。$。subitem并更新该特定项目。 Is there a way on how to do this with DynamoDB? 有没有办法使用DynamoDB做到这一点?

Item: {
  someitem: [
    {
      subitem: "id",
      somevalue: "something"
    }
  ]
}

I would say this is basic functionality but seems not easy to find (or even unsupported) 我会说这是基本功能,但似乎不容易找到(甚至不受支持)

AWS does not permit to modify it in a single update request more info was found in the following answers: updating-a-json-array-in-aws-dynamodb . AWS不允许在单个更新请求中对其进行修改,请在以下答案中找到更多信息:update -a-json-array-in-aws-dynamodb

The solution that they propose is to change the schema from array to {} , or to implement a custom functions and iterate through each array and find your new id to update, so to speak to programatically update your json and then insert whole object. 他们提出的解决方案是将架构从数组更改为{} ,或者实现自定义函数并遍历每个数组并找到要更新的新id,这样可以说以编程方式更新json,然后插入整个对象。

TableName : 'tablename', 
Key : { id: id}, 
ReturnValues : 'ALL_NEW',
UpdateExpression : 'set someitem['+`index`+'].somevalue = :reply_content', 
ExpressionAttributeValues : { ':reply_content' : updateddata }

array element edit via array index 通过数组索引编辑数组元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM