Skip to content

Add support for AggregationExpression in GroupOperation.sum [DATAMONGO-1784] #2693

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

Closed
spring-projects-issues opened this issue Sep 18, 2017 · 2 comments
Assignees
Labels
in: aggregation-framework Aggregation framework support type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link

Sergey Shcherbakov opened DATAMONGO-1784 and commented

After this ticket has been implemented, it is possible to use complex expressions in the aggregation request projections and group method parameters.
For example, there are min(), max(), first() aggregation methods that accept AggregationExpression in the GroupOperation class.
But there is no sum() aggregation method version that accepts AggregationExpression parameter.
Thus, it is not possible to express following MongoDB queries using Spring Data fluent API:

[
     { $match: { "myfield":"X" },
     { $group: {
           _id: { myfield: "$myfield"  },
           count: { $sum: 1 },
           lt5w: { $sum: { $cond:{ if: { $gte: [ "$myDate", new Date(ISODate().getTime() - 1000 * 60 * 60 * 24 * 7 * 5) ] }, then: 1, else: 0 } } },
           gt12w: { $sum: { $cond:{ if: { $gte: [ new Date(ISODate().getTime() - 1000 * 60 * 60 * 24 * 7 * 12), "$myDate"  ] }, then: 1, else: 0 } } }
         }
     }
])

Affects: 1.10.8 (Ingalls SR8), 2.0 GA (Kay)

Referenced from: pull request #501

Backported to: 1.10.8 (Ingalls SR8)

@spring-projects-issues
Copy link
Author

Sergey Shcherbakov commented

Submitted a PR for this
#501
It would be great it could be ported to the Spring Framework 4.0 1.10.x branch as well

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

Thanks Sergey! Will have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: aggregation-framework Aggregation framework support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants