spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.08k forks source link

Add support to use Querydsl without repositories #2994

Open spring-projects-issues opened 5 years ago

spring-projects-issues commented 5 years ago

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:

1 votes, 3 watchers

spring-projects-issues commented 5 years ago

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

fnumrich commented 7 months ago

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