Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 696
spa900 Avatar asked Aug 20 '17 15:08

spa900


People also ask

How do you update multiple items in a DynamoDB table?

The only way to update multiple items at the same time is use TransactionWrite operation provided by DynamoDB. But it comes with a limitation (25 at most for example). So keep in mind with that, you probable should do some limitation in your application as well.

How to update array in DynamoDB?

To update an existing item in an Amazon DynamoDB table, you use the UpdateItem operation. You must provide the key of the item that you want to update. You must also provide an update expression, indicating the attributes that you want to modify and the values that you want to assign to them.

How to update item in DynamoDB?

Updating an item in DynamoDB mainly consists of specifying the full primary key and table name for the item. It requires a new value for each attribute you modify. The operation uses UpdateItem, which modifies the existing items or creates them on discovery of a missing item.

Does DynamoDB support array?

A DynamoDB Set deserializes into an object with its array of items stored under the values property. If we want a Set to deserialize into an array, we'll need to add an unmarshalling step where we assign the values property instead of the deserialized set object itself.


1 Answers

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.

like image 195
Alexandru Olaru Avatar answered Sep 30 '22 19:09

Alexandru Olaru