Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a string set In DDB that is nested inside a map

I am trying to add a string set onto another string set inside an item using the UpdateItem with the Javascript SDK

My Parameters are such:

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

Now this doesn't work as ADD only works on Numbers and Sets and this set is nested under a map and it triggers this error:

Incorrect 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"]. That didn't trigger an error but it also didn't add the value to the set.

Any thoughts on how to do this, sounds like it should be something close to what I am trying.

like image 246
wmfrancia Avatar asked Jan 05 '17 21:01

wmfrancia


1 Answers

You should be able to do it 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)
like image 158
idbehold Avatar answered Sep 24 '22 20:09

idbehold