Krishan Madushanka
Krishan Madushanka

Reputation: 389

Using contains filter in DynamoDB scan with Java - android

I have aws dynamo db table as follows. enter image description here

Now I want to filter it as follows. enter image description here

For that I used the following code and i get 0 results in my code.what's wrong with my code.how to fix it?

public ScanResult getAllMemos() {
    ScanRequest scanRequest = new ScanRequest()
            .withTableName(DB_NAME)
            .withFilterExpression("contains(imgName,thumbnail)");
    return util.getAmazonDynamoDBClient(getActivity()).scan(scanRequest);
}

Without filter expression I get all results.

Upvotes: 1

Views: 2416

Answers (1)

JD D
JD D

Reputation: 8147

Like was discussed in the comments, you need to create an expression attribute value map with the value of the filter and use this.

Try something like this:

public ScanResult getAllMemos() {

    Map<String, AttributeValue> expressionAttributeValues =
        new HashMap<String, AttributeValue>();
    expressionAttributeValues.put(":val", new AttributeValue().withS("thumbnail"));


    ScanRequest scanRequest = new ScanRequest()
            .withTableName(DB_NAME)
            .withFilterExpression("contains(imgName,:val)")
            .withExpressionAttributeValues(expressionAttributeValues);
    return util.getAmazonDynamoDBClient(getActivity()).scan(scanRequest);
}

Upvotes: 2

Related Questions