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?
Asked
Active
Viewed 60 times
0

Kok How Teh
- 3,298
- 6
- 47
- 85
-
Please provide sample code of what you have tried so far. – beautifulcoder Mar 20 '23 at 03:49
1 Answers
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