Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

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

Closed
alcaeus opened this issue Mar 17, 2016 · 0 comments
Labels
Milestone

Comments

@alcaeus
Copy link
Member

alcaeus commented Mar 17, 2016

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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant