0

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?

Kok How Teh
  • 3,298
  • 6
  • 47
  • 85

1 Answers1

0

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"
 };
michail_w
  • 4,318
  • 4
  • 26
  • 43