Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AggregationOperation::toDocument method is deprecated, but MongoTemplate still uses it #4306

Open
MVardumyan opened this issue Feb 27, 2023 · 1 comment · May be fixed by #4309
Open

AggregationOperation::toDocument method is deprecated, but MongoTemplate still uses it #4306

MVardumyan opened this issue Feb 27, 2023 · 1 comment · May be fixed by #4309
Assignees
Labels
type: bug A general bug

Comments

@MVardumyan
Copy link

MVardumyan commented Feb 27, 2023

I need to use custom AggregationOperation for $group operation in my aggregation query. So I've created class like this:

public class CustomGroupingOperation implements AggregationOperation {
    @Override
    public Document toDocument(AggregationOperationContext context) {
        return null;
    }

    @Override
    public List<Document> toPipelineStages(AggregationOperationContext context) {
        return List.of(new Document("$group",
                new Document("_id", new Document("name", new Document("$ifNull", new Object[] {"$name", null})))
                        .append("records", new Document("$push", "$$ROOT"))));
    }

    @Override
    public String getOperator() {
        return AggregationOperation.super.getOperator();
    }
}

According to documentation, toDocument method is deprecated in favor of toPipelineStages method. However, when I use this class with mongoTemplate like this:

AggregationOperation grouping = new CustomGroupingOperation();

TypedAggregation<MyPojoClass> aggregation = newAggregation(
        Object.class,
        match
        grouping
);
return mongoTemplate.aggregate(aggregation, MyPojoClass.class).getMappedResults();

During debugging I see that application enters toDocument method instead of toPipelineStages.
Should I change something in my approach, or is this a bug?

UPD Here are my drivers from spring-boot-starter-data-mongodb-2.7.2.pom:

    <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver-sync</artifactId>
      <version>4.6.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-mongodb</artifactId>
      <version>3.4.2</version>
      <scope>compile</scope>
    </dependency>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 27, 2023
@christophstrobl
Copy link
Member

Good catch - thanks for reporting. The AggregationPipeline is still using it to look up $out stages. We'll take care of this.

@christophstrobl christophstrobl self-assigned this Feb 27, 2023
@christophstrobl christophstrobl added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 27, 2023
@christophstrobl christophstrobl linked a pull request Mar 1, 2023 that will close this issue
@christophstrobl christophstrobl linked a pull request Mar 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants