I have the following POJO.
@Document(collection = "questions")
public class Question {
@Id
private String id;
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
}
I am trying to implement a MongoRepository
query which finds all Question
s that contain a list of tags. I have tried the following:
@Repository
public interface QuestionRepository extends MongoRepository<Question, String> {
List<Question> findByTags(List<String> tags);
}
but this is only working when the List
of tags that I'm passing to the method fully matches the list of tags assigned to the question in Mongo. E.g. if I have a question in Mongo with a list of tags [ "t1", "t2", "t3" ]
it is not returned by findByTags(List)
when I pass [ "t1", "t2" ]
to the method.
I have tried the following as well:
@Repository
public interface QuestionRepository extends MongoRepository<Question, String> {
@Query("{ tags: { $all: ?0 } }")
List<Question> findByTags(List<String> tags);
}
but then my war
could not be deployed to my servlet container at all. (I get the following error in that case:
The web application [backend] appears to have started a thread named [cluster-1-db:27017] but has failed to stop it. This is very likely to create a memory leak.
Would you please advise on how to implement that custom query?