The REST API must only return certain fields from the collection when the user makes a GET request. I added the @Query filter to the repository class as follows:
@Query(value="{ 'clientId' : ?0 }", fields="{ 'clientId' : 1, 'siteUrl' : 1, 'siteName' : 1, 'dateAdded' : 1 }")
Page<sites> findByClientId(Object clientId, Pageable pageable);
But it still returns the entire document for that request and includes all fields. The service method as well seems correct.
public Page<sites> findSitesByCustomer(String name, Pageable pageable){
Clients client = userRepository.findclientsByUsername(name);
if(client.getClientName() != null || !client.getClientName().isEmpty()) {
int clientId = client.getId();
return sitesRepository.findByClientId((long) client.getId(), pageable);
}
return Page.empty();
}
Is there something I am missing?