I have configured a Spring Data Repository (mongoDB) and Author entity as following :
Repository :
public interface AuthorRepository extends MongoRepository< Author, Long > {
Iterable<Author> findByFirstName( String personName );
Iterable<Author> findByFirstNameLike( String personName );
Iterable<Author> findByFirstNameNotLike( String firstName );
}
Entity Class :
@Document( collection = "author" )
@Data
public class Author {
@Id
private String id;
private String firstName;
//..
}
I'm able to run the first two queries without any errors. But the "NotLike" method gives me following runtime error :
Caused by: java.lang.IllegalArgumentException: Unsupported keyword!
at org.springframework.data.mongodb.repository.query.MongoQueryCreator.from(MongoQueryCreator.java:252) ~[spring-data-mongodb-1.8.4.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:114) ~[spring-data-mongodb-1.8.4.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:58) ~[spring-data-mongodb-1.8.4.RELEASE.jar:na]
...
I looked into MongoQueryCreator.from(MongoQueryCreator.java:252)
and found Part.Type.NOT_LIKE
is not handled on switch-case
statement there and its throwing IllegalArgumentException("Unsupported keyword!");
Spring Data MongoDB latest documentation (1.8.4.RELEASE) says NotLike is a supported query keyword. But it seems to be missing in the implementation.
Is there anything missing here or I should raise a bug fix ?
NotLike is still not supported in the current (1.9.1) release of Spring Data MongoDB - see Table 5. Supported keywords for query methods.
Not a bug fix, since the runtime error is consistent with the keyword not being supported, but you can open a feature request on the Spring Data MongoDB JIRA.
In the mean time, to get your code running, you can implement your own findByFirstNameNotLike method, using the Query annotation or even Querydsl for more complex queries.