Reputation: 23
I'm having issues trying to access elements that are nested within a DynamoDB table using conditional expressions. The code I am trying is as follows:
const params = {
TableName: 'Games',
Key: {
id: gameID.id,
},
UpdateExpression: 'SET #players = list_append(#answers , :answer)',
ConditionExpression: '#players CONTAINS :playerID',
ExpressionAttributeNames: {
'#players': 'Players',
'#answers': 'answers',
},
ExpressionAttributeValues: {
':playerID': userID.id,
':answer': tempAnswerList,
},
ReturnValues: 'ALL_NEW',
This version for example raises the error:
Invalid ConditionExpression: Syntax error; token: "CONTAINS", near: "#players CONTAINS :playerID"
Is there a way to look through an array without knowing it's id? Just as a note I have looked for wildcards to use on #players as it is a list but I cannot see one in the docs.
Thanks, Mark
Upvotes: 2
Views: 316
Reputation: 39226
Please change the contains
as mentioned below and try.
ConditionExpression: 'contains (#players, :playerID)',
Upvotes: 2