notionquest
notionquest

Reputation: 39186

Dynamodb - Scan and filter data from numeric list without including key attribute in the filter criteria

I am trying to filter the data from numeric list. I have used Scan with filter by list (i.e. withNS). I have followed the solution in below post. I am neither getting any error nor getting the values in the result set.

DynamoDB java filter list - example

DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
            .withFilterExpression("Comments.UserIds IN (:val1)")
            .withExpressionAttributeValues(eav);

Comments is a complex object which has List userIds (type : Integer). I would like to filter the data by userIds. I don't have all the userIds. If the list contains five user ids, I would have one or two user ids.

Is there a way to achieve this requirement in AWS SDK - Java?

Upvotes: 2

Views: 2996

Answers (1)

notionquest
notionquest

Reputation: 39186

The keywords "contains" solved the problem. Now, I am able to filter the data by few values present in the list.

eav.put(":val1", new AttributeValue().withN(userId));
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression()
        .withFilterExpression("contains (Comments.UserIds, :val1)")
        .withExpressionAttributeValues(eav);

Upvotes: 2

Related Questions