Reputation: 3642
i am trying to call a custom mongoDB query using spring data, but query is not getting called.
Here is my code.
In Controller : call to service method
List<UserProfile> gatheringMembers = userService.getUsersProfile(membersEmail);
Here is service Method that is calling custom mongoDB query
public List<UserProfile> getUsersProfile(List<String> emails){
return userProfileRepository.findAllUsersByEmail(emails);
}
here is my mongoDB repository interface
public interface UserProfileRepository extends MongoRepository<UserProfile, String>, UserProfileRepositoryCustom {
public UserProfile findByEmail(String email);
}
and here is interface
public interface UserProfileRepositoryCustom {
public List<UserProfile> findAllUsersByEmail(List<String> emails);
}
and its implementation
public List<UserProfile> findAllUsersByEmail(List<String> emails) {
logger.info("getting all users profiles");
Query query = new Query(where("email").in(emails));
return mongoOperations.find(query, UserProfile.class);
}
when i run the code, i am getting empty list in controller. findByEmail
is working fine. Can any one kindly help me whats wrong in this code.
Regards,
Upvotes: 0
Views: 565
Reputation: 3642
After searching a bit more, i found a solution to my answer, that was not the code problem but actually the configuration problem. For those who face the same problem i will add the solution. After adding repository-impl-postfix="CustomImpl"
it started working.
Before :
<mongo:repositories base-package="com.app.repositories"/>
After :
<mongo:repositories base-package="com.app.repositories" repository-impl-postfix="CustomImpl" />
Upvotes: 1