Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-1784

Add support for AggregationExpression in GroupOperation.sum

    XMLWordPrintable

    Details

      Description

      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 } } }
               }
           }
      ])
      

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            Smollet Sergey Shcherbakov
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: