java - Repository query with a List parameter in Spring Data MongoDB -


i have 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 trying implement mongorepository query finds questions contain list of tags. have tried following:

@repository public interface questionrepository extends mongorepository<question, string> {     list<question> findbytags(list<string> tags); } 

but working when list of tags i'm passing method matches list of tags assigned question in mongo. e.g. if have question in mongo list of tags [ "t1", "t2", "t3" ] not returned findbytags(list) when pass [ "t1", "t2" ] method.

i have tried following well:

@repository public interface questionrepository extends mongorepository<question, string> {     @query("{ tags: { $all: ?0 } }")     list<question> findbytags(list<string> tags); } 

but war not deployed servlet container @ all. (i following error in case:

the web application [backend] appears have started thread named [cluster-1-db:27017] has failed stop it. create memory leak. 

would please advise on how implement custom query?

i answer own question have found answer myself. following section in spring data mongodb documentation lists supported keywords used spring query derivation:

http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#repository-query-keywords

the following implementation works use case described above:

@repository public interface questionrepository extends mongorepository<question, string> {      list<question> findbytagsin(list<string> tags); } 

Comments