SebDez
SebDez

Reputation: 3

Operator OR in dynamo query

I'm trying to make a query with aws-sdk and 'OR' operator, like this :

{ TableName: 'Movies',
  KeyConditionExpression: '#year = :year or #title = :title',
  ExpressionAttributeNames: { '#year': 'year', '#title': 'title' },
  ExpressionAttributeValues: { ':year': 1985, ':title': 'The Breakfast Club' } }

And I get this :

{ [ValidationException: Invalid operator used in KeyConditionExpression: OR]
  message: 'Invalid operator used in KeyConditionExpression: OR',
  code: 'ValidationException',
  time: Mon Apr 04 2016 11:36:22 GMT+0200 (Paris, Madrid (heure d’été)),
  requestId: '827M149G5IMJ1BPM4J883DMCJNVV4KQNSO5AEMVJF66Q9ASUAAJG',
  statusCode: 400,
  retryable: false,
  retryDelay: 0 }

I'm using the standard amazon dynamo sample data file (Movies, here) -

So my question is, how can I use an operator 'OR' for Dynamo query ?

Thanks :)

Upvotes: 0

Views: 3616

Answers (2)

SebDez
SebDez

Reputation: 3

Thank you @x-code this helped me to see that I was querying on my keys and not my attributes.

So I did like this :

{
    TableName: "Movies",
    FilterExpression: "#title = :title or #title = :titletwo",
    ExpressionAttributeNames: {
        "#title": "title"
    },
    ExpressionAttributeValues: {
         ":title": {'S':'King Kong'},
         ":titletwo" : {'S':'Lifeboat'}
    }
}

I also used a scan method instead of a query which hash to be mentioned in the query conditions.

Upvotes: 0

x-code
x-code

Reputation: 608

Try using FilterExpression like

'FilterExpression' => '#year = :year or title = :title' ,

i presume keyconditions refer to hash and range key conditions... if your year and title attributes are not hash and range keys, try using Filterexpression or Condition expression, please correct me if im wrong....

Upvotes: 1

Related Questions