我有以下几点建议.
@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;
}
}
我正在try 实现一个MongoRepository
查询,它将查找所有包含标签列表的Question
个.我try 了以下方法:
@Repository
public interface QuestionRepository extends MongoRepository<Question, String> {
List<Question> findByTags(List<String> tags);
}
但只有当我传递给该方法的List
个标记与Mongo中分配给问题的标记列表完全匹配时,这才有效.例如,如果我在Mongo中有一个带有标签[ "t1", "t2", "t3" ]
列表的问题,当我将[ "t1", "t2" ]
传递给该方法时,findByTags(List)
不会返回该问题.
我也try 过以下方法:
@Repository
public interface QuestionRepository extends MongoRepository<Question, String> {
@Query("{ tags: { $all: ?0 } }")
List<Question> findByTags(List<String> tags);
}
但是,我的war
完全无法部署到我的servlet容器中.(在这种情况下,我得到以下错误:
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.
请您就如何实现该定制查询提供建议?