I'm using QueryDSL predicates with Spring Data Mongodb. However, I'm facing situations where I have to use the Query API with MongoTemplate (for instance to filter fields to fetch from Mongo). Here is a simple example:
public Stream<MyModel> findSummary(Predicate predicate){
Query query = new Query();
query.fields.include("field1").include("field2");
return mongoTemplate.stream(query, MyModel.class);
}
I would like to transform my Predicate into a Criteria so that I could do something like:
Query query = new Query();
query.addCriteria(XXXXX.toCriteria(predicate));
However I cannot find such utility class.
I've found that a QueryDSL Predicate can be visited and so I started implementing a custom Visitor (com.mysema.query.types.Visitor) but the Criteria API was not designed for this purpose: for example implementing the simple "and" operator of QueryDSL (com.mysema.query.types.Ops#AND) has to be turned into something like
<result of left argument visit assumed to be a Criteria>.and("<path of right argument>").<operator of right argument>(<result of right argument visit>);
Can someone suggest an approach to make QueryDSL Predicates and Spring Data Mongodb Query interoperate ?
Thanks
Benoit