1

I'm just trying to add a number to a number set in DynamoDB. This expression was working with an untyped list. But to save space since it will just be storing numbers I moved everything to plain number sets. Now no matter how much I tinker with it I can't get it to go through.

var phoneID = req.body.PhoneID;
var category = req.body.ratingCategory;
var ratingToAdd = [Number(req.body.rating)]

var dbparams = {
"TableName": "Venue_Ratings",
Key: {
   "PhoneID" : phoneID
},
"UpdateExpression": "SET #categoryName =  list_append(#categoryName, :rating)",
"ExpressionAttributeNames" : {
    "#categoryName" : category
},
"ExpressionAttributeValues": {
    ":rating": ratingToAdd
},
"ReturnValues": "ALL_NEW"
};

This error is being thrown An operand in the update expression has an incorrect data type

I have also tried changing the update expression to an ADD expression instead like so ADD #categoryName :rating.

I've tried changing ratingToAdd to a plain number not in an array, a string in an array, and a plain string not in an array.

I'm calling the db using the docClient.update method.

I have verified that the sets in the db are in fact number sets and that they exist.

What am I missing here? Thanks for the help.

1 Answer 1

2

The below code should add the number to the Number Set (i.e. DynamoDB data type 'NS').

Use this function with ADD in UpdateExpression:-

docClient.createSet([Number(5)])

Code:-

var params = {
        TableName : "Movies",
        Key : {
            "yearkey" : 2016,
            "title" : "The Big New Movie 1"
        },
        UpdateExpression : "ADD #category :categorySet",
        ExpressionAttributeNames: {
            '#category' : 'category'
        },
        ExpressionAttributeValues: {':categorySet' : docClient.createSet( [Number(5)])},
        ReturnValues: 'UPDATED_NEW'
    };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.