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!