You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I need to use custom AggregationOperation for
$group
operation in my aggregation query. So I've created class like this:According to documentation,
toDocument
method is deprecated in favor oftoPipelineStages
method. However, when I use this class with mongoTemplate like this:During debugging I see that application enters
toDocument
method instead oftoPipelineStages
.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
:The text was updated successfully, but these errors were encountered: