I need to check list of data with contains function is DynamoDB. Following is my Java Code,
List<String> dataList = new ArrayList<>();
I am inserting the above list inside a JSON called Data.
Map<String, AttributeValue> valueMap = new HashMap<>();
valueMap.put(":v", new AttributeValue().withS(String.valueOf(dataList)));
Map<String, String> nameMap = new HashMap<>();
nameMap.put("#list", "Data.list");
DynamoDBQueryExpression<> queryExpression = new DynamoDBQueryExpression<>()
.withFilterExpression("contains(#list, :v)")
.withExpressionAttributeNames(nameMap)
.withExpressionAttributeValues(valueMap)
.withConsistentRead(false);
I used the above approach but it is not working. What I need is I need to filter data if any of the list values contains in the dynamo db inserted list values. The list data is inside Json. So what I am doing wrong here? can anybody help me? Thanks in advance.
withKeyConditionExpressionas part of buildingDynamoDBQueryExpression.FilterExpressionis not improving your RCUs consumption. It adds very little value. I prefer having clean query objects (ddbMapper.query(Object)) and filtering post getting response.From the docs -
Note: If still looking to do it in DynamoDB query, you need to ensure that
AttributeValuetype provided is correct.From the docs -
So, here change from
new AttributeValue().withStonew AttributeValue().withSSto apply over list. Note that, you will still need to bring your object down toAttributeValuegranularity which DDB understands.This doc has more advanced samples.