Skip to content

Instantly share code, notes, and snippets.

@thomasmartin-whoz
Last active December 12, 2022 10:48
Show Gist options
  • Save thomasmartin-whoz/0dcf4b577c7d31e0ab6baa3312bc8118 to your computer and use it in GitHub Desktop.
Save thomasmartin-whoz/0dcf4b577c7d31e0ab6baa3312bc8118 to your computer and use it in GitHub Desktop.
@Repository
class PersonRepositoryImpl implements PersonRepositoryCustom {
@Autowired
MongoTemplate mongoTemplate
@Override
List<Person> findByIdsOrFirstNameOrLastName(List<String> personIds, String firstName, String lastName){
Criteria allCriteria = [
personIds?.with { Criteria.where('_id').in(it) },
firstName?.with { Criteria.where('firstName').is(it) },
lastName?.with { Criteria.where('lastName').is(it) },
].findAll()
return mongoTemplate.find(Criteria().andOperator(allCriteria), Person.class)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment