, | Array | Array [ Array , ] aggregate (
, | Array [ Object , ] docs
) {

Locally apply a MongoDB aggregation pipeline. Does not affect the input documents. Optionally returns the results of each individual stage as well as the final result.

Arguments

| Array [ Object , ] docs

An Array of documents to process.

| Array [ Object , ] pipeline

An Array of stage operator specifications used to select/modify the source documents.

optional
| Boolean keepStages

If true, the return value is an Array containing each Array of results produced by each stage. Otherwise the return value is the final result Array.

Return Values

| Array | Array [ Array , ]

Either the final result set or an Array containing the result set of each stage.