Reputation: 129
I have a DynamoDBScanExpression that scans my table in DynamoDB service. The DB mapping class is Item.class
.
The reason I'm using ScanExpression
is that it is an adapter to a ListView.
What I want to do, is to filter the ScanExpression
results by boolean
, so I'll get only the results where the attribute "text" will be true
.
I've tried to check when the value of the attribute is equal to the String "true", but it didn't work.
DynamoDBScanExpression dbScanExpression = new DynamoDBScanExpression();
Condition condition = new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue("true"));
dbScanExpression.addFilterCondition("text", condition);
List<Item> itemsList = dbMapper.scan(Item.class, dbScanExpression);
How can I filter the ScanExpression to get only rows with true
value in the "text" attribute?
Upvotes: 2
Views: 1855
Reputation: 39186
Define the field using the below annotation and scan the table as mentioned below (i.e. using new AttributeValue().withBOOL(true)).
@DynamoDBNativeBoolean
@DynamoDBAttribute(attributeName = "text")
public Boolean getStatusCode() {
return text;
}
Condition condition = new Condition().withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withBOOL(true));
dbScanExpression.addFilterCondition("text", condition);
Upvotes: 3