简体   繁体   中英

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? For example: In MongoDB you can search for someitem.$.subitem and update that specific item. Is there a way on how to do this with 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 .

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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