Mark Addis
Mark Addis

Reputation: 23

How to access nested elements in DynamoDB with NodeJS and Conditional Expresions?

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"

Example DB Schema

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

Answers (1)

notionquest
notionquest

Reputation: 39226

Please change the contains as mentioned below and try.

ConditionExpression: 'contains (#players, :playerID)',

Upvotes: 2

Related Questions