1

I wanted to know if there was a way to use QueryDsl's TypeSafe approach to perform a projection on a query in conjunction with Spring Data.

Like for example :

public interface ColorCollectionRepository extends MongoRepository<ColorCollection, String>, QuerydslPredicateExecutor<ColorCollection> {


    Optional<ColorCollection> findByCodeIs(String code);


    List<ColorCollection> findAll(Predicate predicate);

}

And running a query where I would like to exclude a field named "references"

QColorCollection qColorCollection = QColorCollection.colorCollection;
qColorCollection.code.eq("code");
qColorCollection.exclude("references");

Thanks

ufasoli
  • 1,038
  • 2
  • 19
  • 41

1 Answers1

0

Querydsl doesn't support projections for mongodb as of now. You need to implement custom solution for it to work.

I have developed a custom solution which is useful if you want to include specific fields. You may check it here - https://stackoverflow.com/a/66152979/8949877

Harshit
  • 1,334
  • 1
  • 9
  • 23