Spring data Mongo with QueryDSL- return custom dto instead of actual documents

36 Views Asked by At

Scenario ========

Find and return dto (not actual document) from Mongo DB using SpringdataMongo and QueryDsl

scanario

document

Customer{ name, age, city, zip }

JPA repository

interface CustomerQuerydslRepository extends CrudRepository<Customer, String>, QuerydslPredicateExecutor { }

Service Call

{ ... @Autowired CustomerQuerydslRepository repository;

List result = repository.findAll(QCustomer.customer.lastname.eq("Matthews"));

}

since my original document is large, I want to return only few fields and needs that to be mapped to a dto below

dto

CustomerDto{ name, age }

my current workaround is to map returned documents to dto in the service layer but looking for more optimized ways using QueryDSL itself.

0

There are 0 best solutions below