I have a table of "team memberships" with primary partition key of "team_id" , a primary sort key of "email" and a GSI with "email" as partition key.
Given a list of emails I would like to find all the memberships for all the emails in the list in the most efficient way possible.
I know that for a single email I can do the following:
Membership membership = new Membership();
membership.setEmail(email.toLowerCase());
DynamoDBQueryExpression<Membership> expression = new DynamoDBQueryExpression<Membership>()
.withHashKeyValues(membership)
.withIndexName(EMAIL_INDEX)
.withConsistentRead(false);
return mapper.query(Membership.class, expression);
which returns a list of memberships for the given email.
(So for my list of emails, I could do the above for each email in the list, but I would like to know if it is possible to do in one step).
I would like to be able to do something like:
List<Membership> memberships = allEmails.stream().map(email -> {
Membership m = new Membership();
m.setEmail(email.toLowerCase());
return m;
}).collect(Collectors.toList());
DynamoDBQueryExpression<Membership> expression = new DynamoDBQueryExpression<Membership>()
.withHashKeyValues(memberships) // <--- passing a list
.withIndexName(EMAIL_INDEX)
.withConsistentRead(false);
which clearly doesn't work.
What are the alternatives?