Reputation: 53
I am using Spring Boot and MongoDB, and am trying to expose them over REST using Spring Rest Repositories.
I have a Mongo collection called user
and the Java domain model class called User
. My Rest Repository looks like this:
@RepositoryRestResource( collectionResourceRel = "users", path = "users")
public interface UserRepository extends MongoRepository<User, String> {
public User findByEmail(@Param("email") String email);
}
With this in place, I get the advertised benefits of the resource getting automatically exposed over REST. GET, PUT, POST all that jazz.
What I find though is that when I rename the Mongo collection to User
, it doesn't find records on the /users
endpoint. It is almost as if Spring REST Repositories assumes that the collection name will be in lowercase (yes, I did come across the documentation here - https://docs.spring.io/spring-data/rest/docs/current-SNAPSHOT/reference/html/)
Spring Data REST exposes a collection resource named after the uncapitalized, pluralized version of the domain class the exported repository is handling. Both the name of the resource and the path can be customized using the @RepositoryRestResource on the repository interface.
What I am after is a way to get this configured so that I can use a collection name like User
instead of user
.
I have searched a fair bit, but haven't been able to come up with answers.
Any help much appreciated! Cheers!
Upvotes: 1
Views: 246
Reputation: 1685
I experienced the same problem, In my case I have annotated the User class with @Document but I was missing to add the value :
@Document("User")
javadoc of value attribute:
The collection the document representing the entity is supposed to be stored in. If not configured, a default collection name will be derived from the type's name.
So by default if not configured, seems to use the Class name in lowerCamelCase.
Upvotes: 0