Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS DynamoDB scan FilterExpression use not equals on String in list

I have a List with ID's of type String. I want to scan DynamoDB and get a result list with items that do NOT have these ID's. But I can not figure out how to type the filter expression. ReviewId is the primary partition key of type String.

Map<String, AttributeValue> eav = new HashMap<>();
eav.put(":idFilter", new AttributeValue().withSS(idFilter));

DynamoDBScanExpression scanExp = new DynamoDBScanExpression()
          .withFilterExpression("ReviewId <> (:idFilter)")
          .withExpressionAttributeValues(eav);

The above filter expression is valid but it still always returns items with id's in the list. I have also tried to include the word in before and after the <> operator.

like image 341
Jonathan Andersson Avatar asked Mar 10 '23 15:03

Jonathan Andersson


1 Answers

You can change the filter expression as below and populate the ExpressionAttributeValues with values for keys :reviewId1, :reviewId2, :reviewId3.

FilterExpression: "NOT ReviewId in (:reviewId1, :reviewId2, :reviewId3)"

Note:-

Unfortunately, you can't keep the idFilter as SET or LIST to compare with String attribute of DynamoDB.

like image 59
notionquest Avatar answered Apr 07 '23 15:04

notionquest