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!

Catti
  • 11
  • 1
  • 1
    Your question is similar to [this](https://stackoverflow.com/questions/45784042/dynamodb-update-inside-an-array-of-objects-nodejs) issue. It will help you out. – r_dmr Aug 24 '21 at 16:14

0 Answers0