spring-data-mongodb
spring-data-mongodb copied to clipboard
Add support to use Querydsl without repositories
Cesar Tron-Lozai opened DATAMONGO-2177 and commented
When migrating to 2.1.3 I noticed that the asDBobject method of SpringDataMongodbQuery method has been removed
I tried to work around it by trying to extend the class but most of the useful methods are either private or package private which makes it really hard to do that sort of things.
The reason I need that is because I want to to use a QueryDsl predicate into an aggregation pipeline.
I used to do it with something like that:
final SpringDataMongodbQuery<Foo> query = new SpringDataMongodbQuery<>(template, Opportunity.class).where(predicate);
final BasicDBObject dbObject = (BasicDBObject) query.asDBObject();
Then I would do some modification on the DBObject to add a prefix required by the aggregation and finally transform it into a CriteriaDefinition:
private CriteriaDefinition fromDocument(Document dbObject) {
return new CriteriaDefinition() {
@Override
public Document getCriteriaObject() {
return dbObject;
}
@Override
public String getKey() {
return null;
}
};
}
Now that the asDBObject method is method is gone, how can I get a Document or DBobject from a Predicate or a query?
Issue Links:
- DATAMONGO-2233 Convert Querydsl Predicate to org.bson.Document ("is duplicated by")
1 votes, 3 watchers
Mark Paluch commented
We migrated in Spring Data MongoDB 2.1 off Querydsl's MongoDB support classes towards our own types as Querydsl requires DBObject API usage and we're already on the Document API. Currently, your only option would be subclassing SpringDataMongodbQuery and increasing createQuery() visibility to public.
Using Querydsl together with Aggregation is a neat approach. Let's see whether we can provide dedicated support for this kind of queries out of the box
Hi @mp911de,
Using Querydsl together with Aggregation is a neat approach. Let's see whether we can provide dedicated support for this kind of queries out of the box
Is there anything new regarding this?
Best Regards, Frank