How to update a rowset In a DDB that is nested inside a map

I am trying to add a rowset to another rowset inside an element using UpdateItem with the Javascript SDK

My options are as follows:

var params = { Key: { "MyKeyName" : {"S" : "MyKeyValue" } }, TableName: "TableName", ExpressionAttributeNames: { "#Name1" : "mapName" }, ExpressionAttributeValues: { ":Value1" : {"M" : {"StringSetName" : { "SS": ["ValueToAdd"] } } } }, UpdateExpression: "ADD #Name1 :Value1" }; 

Now this does not work, since ADD only works with Numbers and Sets, and this set is nested in the map and causes this error:

Invalid operand type for operator or function; operator: ADD, operand type: MAP

I tried changing the attribute name to mapName.M.StringSetName and made the value {"SS" : ["ValueToAdd"] . This did not cause an error, but also did not add value to the set.

Any thoughts on how to do this sound like it should be something close to what I'm trying.

+5
source share
1 answer

You can do this with this:

 var AWS = require('aws-sdk') var DB = new AWS.DynamoDB.DocumentClient() var params = { TableName: "TableName", Key: { MyKeyName: "MyKeyValue" }, UpdateExpression: "ADD #Name1.StringSetName :Value1", ExpressionAttributeNames: { "#Name1" : "mapName" }, ExpressionAttributeValues: { ":Value1": DB.createSet(["ValueToAdd"]) } } DB.update(params) 
+3
source

Source: https://habr.com/ru/post/1262385/


All Articles