Library allowing easy access to the mongo aggregate framework

1.3.1 2016-02-08 07:51 UTC

This package is not auto-updated.

Last update: 2020-09-18 20:44:05 UTC


Build Status StyleCI Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight


Library allowing easy access to the mongo aggregate framework


This library constructs aggregation pipelines using builders. You can add stages (instances of AggregationInterface), collections of stages (AggregationBags) or other builders to construct your pipeline. A special builder is the UnwindBuilder. This Builder will create a pipeline that can unwind both strings and arrays and databases that has the two mixed (the latter should be avoided). Basically the builder will transform any mongo field to an array and then unwind that array.

Example usage of the UnwindBuilder is in its Test:

Supported stages

This library currently supports the following stages in the aggregate framwork:

Class Operator Description
Match $match
Project $project
Unwind $unwind
Group $group
Sort $sort
RangeProjection A ranged projection stage, a special kind of $project which can map ranges (for example: 1 to 10) to strings (for example to 'low').

Supported operations

Within the stages operations can be used, these are currently supported:

Class Operator Description
Sum $sum
Condition $cond
Push $push
WeekOperation $week
FieldOperation Rename a field in a projection (example: {$project: {my_field: {'$'}}})
ArrayOperation Add an expression in a projection using a mongo array (example: $operation = new ArrayOperation(['$year' => '$somedate']))


The library adds a class EmbeddedCollection which can be used to create a (temporary) collection that embeds documents that another collection has referenced.

Stages or operations that aren't supported by the library, can still be used by constructing arrays. However, creating a class and the abstraction layer that comes with that is to be preferred.