doctrine/mongodb

Aggregation builder does not support arbitrary operators for ID in group stages

alcaeus opened this issue · 0 comments

Let's take the following aggregation pipeline:

[
    { $group: {
        _id: { $dayOfMonth: '$date' },
        signups: { $sum: 1 }
    }}
]

In the aggregation builder this stage can't be built since the Match class only offers accumulators (sum, avg, etc.). This was done to make it clear to the user that using any available aggregation operator is not possible. Thus, a workaround using a $project stage has to be built:

->project()
    ->field('day')
    ->dayOfMonth('$date')
->group()
    ->field('_id')
    ->expression('$day')
    ->field('signups')
    ->sum(1)

It would be better if I were able to do this:

->group()
    ->field('_id')
    ->dayOfMonth('$date')
    ->field('signups')
    ->sum(1)