0

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,

1 Answer 1

1

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" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.