11

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)

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
spa900
  • 927
  • 9
  • 19
  • Possible duplicate of [Dynamodb - Update value of JSON object in array of objects](https://stackoverflow.com/questions/40987976/dynamodb-update-value-of-json-object-in-array-of-objects) – Adil May 24 '18 at 09:47

2 Answers2

4

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.

Alexandru Olaru
  • 6,842
  • 6
  • 27
  • 53
4
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