How to have FilterExpression with multiple conditions in dynamodb

JithPS picture JithPS · Jun 9, 2016 · Viewed 34k times · Source

I am trying to do table scan on dynamodb Below is the code which is in javascript

var params = {
    TableName: 'Contacts',
    FilterExpression: 'begins_with(CustomerName,:value)OR begins_with(CustomerName,:val) ', 
    ExpressionAttributeValues: { 
        ':value': {'S':'S'},
        ':val':{'S':'E'},
      },
    Select: 'ALL_ATTRIBUTES', 
 };

 dynamodb.scan(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

But I couldn't try the same using botot3.

Below is what I could achieve so far

response = table.scan(
                  Select= 'ALL_ATTRIBUTES',
                  FilterExpression=Attr('CustomerName').begins_with("S") 
                  )

I couldn't understand how to add the OR condition. If I add, it shows error

Answer

JithPS picture JithPS · Jun 13, 2016

For AND '&' is used and for OR '|' is used

  response = table.scan(
              Select= 'ALL_ATTRIBUTES',
              FilterExpression=Attr('CustomerName').begins_with("S") | Attr('CustomerName').begins_with("S") 
              )