0

I'm trying to append a new string into my "savedPosts" array and my first attempt was to read the previous data, then append the new element and finally update. Although after checking documentation, it says that I can skip the reading step and update my existing list with one call.

My code so far:

await UserModel.update({
  awsCognitoId: req.user,
  savedPosts: {$add: postId}
});

Error:

{
    "code": "ValidationException",
    "message": "Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: STRING, typeSet: ALLOWED_FOR_ADD_OPERAND"
}

1
  • It looks like you're using a framework. Can you include that information in your question? Commented May 6, 2021 at 22:25

1 Answer 1

1

I had the same issue and what I did to fix this was change my UpdateExpression from an ADD to a SET. I also used the list_append() to accomplish this. Please ensure you're appending 2 Arrays.

Please take a look at this url https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.UpdateExpressions.html Jump to Appending Elements to a List

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.