'search elements by email is not working spring data mongo

I am adding a search feature to find players by a keyword, this keyword can be:

  • first name
  • last name
  • username
  • email

my method work correctly when I test searching by the three first fields, but it's showing all data on searching by email and it's not retrieving the exact element although the emails are unique in my database

The method in the service class

public List<Player> findPlayer(String keyword) {
    TextCriteria criteria = TextCriteria.forDefaultLanguage()
            .matchingAny(keyword.split(" "));
    Sort sort = Sort.by("score");
    return playerRepository.findAllBy(criteria, sort);
}

The following code is in the repository

List<Player> findAllBy(TextCriteria textCriteria, Sort sort);

and the annotation @TextIndexed is added in the desired fields to index the data



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source