We are using $all in mongodb repository like below:
@Query(value = "{ 'subscriptions' : {$all : ?0 }}")
public List<ContentItem> findBySubscription(String[] subscriptionCode);
it works good for mongo but we need its alternative in dynamodb
The below solution uses AWS SDK DynamoDB . Currently, I think there is only community version of Spring data available for DynamoDB. So, I have provided the solution using AWS SDK .
The CONTAINS
comparison operator can be used to search for the values in LIST data type.
CONTAINS is supported for lists: When evaluating "a CONTAINS b", "a" can be a list; however, "b" cannot be a set, a map, or a list.
Example:-
QuerySpec querySpec = new QuerySpec();
querySpec.withKeyConditionExpression("yearkey = :yearval and title = :title")
.withFilterExpression("contains (subscriptions, :subscriptions)")
.withValueMap(
new ValueMap().withNumber(":yearval", yearKey)
.withString(":title", title)
.withString(":subscriptions", subscriptions));
Edit:-
Currently, the second parameter can't be list because the API can't process it as per the specification. The workaround would be to use AND condition with multiple CONTAINS . Example below:-
.withFilterExpression("contains (subscriptions, :subscriptions1) AND contains (subscriptions, :subscriptions2)")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.