I\'m currently using Spring Boot to create a REST API with a mongodb backend. Is it possible to only expose certain fields when viewing a specific item, and not a list of it
You have to add @Query annotation on the find method in the repository and specify the fields parameter:
public interface PersonRepository extends MongoRepository
@Query(value="{ 'firstname' : ?0 }", fields="{ 'firstname' : 1, 'lastname' : 1}")
List findByThePersonsFirstname(String firstname);
}
See: http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongodb.repositories.queries.json-based