Skip to content

Aggregate subdocument arrays #918

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

Merged
merged 3 commits into from
Oct 7, 2016

Conversation

fieteboerner
Copy link
Contributor

With this code it is possible to use aggregation functions (sum, count, max, min, avg, ...) on subdocument arrays (embedsMany). To use this functionality you have to pass array.*.field to the corresponding aggregation function.

Check out the code example in testSubdocumentArrayAggregate in QueryBuilderTest.php.

As you can see with this solution it is very simple to apply the aggregation functions instead of writing complex raw aggregations. In my scenario, the code is much simpler and cleaner.

I would be glad to get feedback if you are interested to this functionality, or if you have suggestions for improvements or alternatives.

@pi0 pi0 mentioned this pull request Sep 1, 2016
@pi0
Copy link
Contributor

pi0 commented Sep 1, 2016

There are breaking changes on master so unitTests are failing. would you please follow This steps to rebase this PR with master branch and running UnitTests against latest changes ?

Thanks :)

Fiete Börner added 3 commits September 1, 2016 11:14
example:
    Model::sum('subarray.*.price');

this method is much simpler as to use as complex raw aggregations

for this function a $unwind directive will be pushed in pipeline before $group
change test for different scenarios
@fieteboerner
Copy link
Contributor Author

ok, i've just updated it :)

@jenssegers jenssegers merged commit 81ae5a6 into mongodb:master Oct 7, 2016
mnphpexpert added a commit to mnphpexpert/laravel-mongodb that referenced this pull request Sep 2, 2024
* add sub document aggregation array functionality

example:
    Model::sum('subarray.*.price');

this method is much simpler as to use as complex raw aggregations

for this function a $unwind directive will be pushed in pipeline before $group

* change testSubdocumentArrayAggregate

change test for different scenarios

* rebase to latest master and fix style ci issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants