1

I have this code, What I am trying to do is create a match and then add the match id to the property "playedMatches" in the player table.

My code creates the match then I add the ID of that created match to the array for "playedMatches" in the player table, everything works fine. However, when I want to push the second played match ID to the array, it deletes all the items in the array and replaces it for the new one created.

In MongoDB I would use the $push Update Operator. Is there something similar I can use for Dynamo DB?

I have also tried with createSet and I get errors every time.

What am I doing wrong?

This is the table structure:

id: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx

img:    

name: john doe

playedMatches: [xxxxx-xxxxx-xxxx-xxxx-xxxxx]

I want push new id's into playedMatches


  const matchId = ['987654321'];
  const duplicatedId = '987654321';

  const putDataParams = {
    TableName: table,
    Key: {
      id,
    },
    UpdateExpression: 'set playedMatches = list_append(playedMatches, :matchId)',
    ConditionExpression: 'not contains (playedMatches, :duplicatedId)',
    ExpressionAttributeValues: {
      ':matchId': matchId,
      ':duplicatedId': duplicatedId,
    },
    ReturnValues: 'UPDATED_NEW',
  };

Thanks a lot!

1
  • 1
    Your question is similar to this issue. It will help you out. Commented Aug 24, 2021 at 16:14

0

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.