Aggregation Pipeline

The aggregation command, with its aggregation pipeline, is an extremely powerful tool that allows to easily construct complex queries.


        "$match": {
            "example": 15
        "$project": {
            "other": 1

This example aggregation query, first filters all records from the collection named “secrets” where the field “example” is equal to 15. In a second step, it applies a projection on the field named “other”, which as a consequence, is the only field shown in the result.

This query is equivalent to the following SQL query:

SELECT "other"
FROM "secrets"
WHERE "example" = 15


The MongoDB Query Language supports different possible pipeline stages. In the following, we describe all stages supported by Polypheny.


Adds a new field to an existing record.


Counts the number of records from the previous stage.


Groups the record by a needed _id field, and additionally allows specifying other aggregations.


Limits the retrieved records to the given amount of records.


Filters the previous stage with the provided condition.


Allows to apply an inclusive or exclusive projection to the records.


This is an alias for $replaceWith that allows to replace a document with one of its subfields.

Attention: This stage is only possible when querying a document schema.


This is an alias for $addFields, which allows adding additional entries to an existing record during retrieval.


Skips the specified amount of records.


Allows sorting by the given entities.


Thi is an alias for multiple exclusive projections.


Allows to deconstruct an array into multiple records for each entry.

Attention: This stage is only possible when querying a document schema.