How do I scan a DynamoDB table in C# returning records matching any of the 2 columns provided in a ScanFilter
- OR
operator? For example, column "a" == value OR "b" == value. Is this supported by the API? Currently I am scanning the table twice for each of the conditions. Anyway to optimize this?
OR
operator is supported.
First, take a look on docs about running table scan: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetScanning.html
Then, take a look on the expression language: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
Finally, your scan request should look similar to this one:
var forumScanRequest = new ScanRequest
{
TableName = "ProductCatalog",
ExpressionAttributeValues = new Dictionary<string,AttributeValue> {
{":val", new AttributeValue { N = "0" }}
},
FilterExpression = "a = :val OR b = :val",
ProjectionExpression = "Id"
};