MongoDB Aggregation Pipeline Operatos

Last update on April 06 2017 11:28:58 (UTC/GMT +8 hours)

Description

The MongoDB, aggregation pipeline is a framework for data aggregation modeled on the concept of data processing pipelines. Documents enter as an input into multi-stage pipeline which transforms the documents into an aggregated results.

The MongoDB aggregation pipeline consists various stages. Each stage transforms the documents passes through the pipeline. In this stage it is not needed to produce one output document for every input document. The pipeline stages can appear multiple times in the pipeline.

Here is a list of MongoDB Aggregation Pipeline Operators in the table below.

Stages operators:

The $project function in MongoDB passes along the documents with only the specified fields to the next stage in the pipeline. This may be the existing fields from the input documents or newly computed fields.

The MongoDB $unwind stages operator is used to deconstructs an array field from the input documents to output a document for each element. Every output document is the input document with the value of the array field replaced by the element.

The MongoDB $group stages operator groups the documents by some specified expression and groups the document for each distinct grouping. An _id field in the output documents contains the distinct group by key. The output documents can also contain computed fields that hold the values of some accumulator expression grouped by the $group‘s _id field. This operator does not order its output documents.

The MongoDB $out write the resulting document of the aggregation pipeline to a specified collection. The $out operator must be the last stage in the pipeline. The $out operator lets the aggregation framework return result sets of any size.

The MongoDB $setDifference operators takes exactly two argument expressions i.e. two sets and returns an array containing the elements that only exist in the first set; i.e. performs a relative complement of the second set relative to the first.

The MongoDB $setIsSubset operators takes exactly two argument expressions i.e. two sets and returns true when the first array is a subset of the second, including when the first array equals the second array, and false otherwise.

The MongoDB $anyElementTrue operators takes a single argument expression. i.e. a set and returns true if any elements of the set evaluate to true; otherwise, returns false. An empty array returns false.