简体   繁体   中英

Calling custom mongoDB query with spring data fails

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,

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" />

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM