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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With