Get the App
SLTechnology News&Howtos  ›  Database  › 

Stages of MongoDB pipeline aggregation

Shulou Source: shulou.com Published: 2022-06-01 09:52:38 10月01日 Update

Each stage of pipeline polymerization

Name

Description

$project

Transform documents in the flow, such as by adding new fields or removing existing fields. For each input document, output one document.

$match

Filter the document stream to allow only matching documents to move on to the next pipeline phase without modification. $match uses a standard MongoDB query. For each input document, the output is either one document (match one) or zero documents (no match).

$redact

Transform each document in the flow by limiting the content of the document (based on its own information stored in the document). Combine the functions of $project and $match. Can be used to implement field-level revisions. For each input document, the output is either one or another document.

$limit

When n specifies a value, the first n documents are passed to the pipe without modification. For each input document, the output is either one document (for the first n documents) or zero documents (after the first n documents).

$skip

When n is specified as the skip number, the first n documents are skipped and the remaining documents are passed to the pipe without modification. For each input document, the output is either zero (for the first n documents) or one document (if it is after the first n documents).

$unwind

For each element, output a document from the input document deconstructed array field. Each output document replaces the array with element values. For each input document, when n is the number of array elements, output n documents, for an empty array can be zero.

$group

Group the input document by specifying the identifier expression, and apply the accumulator expression, if specified, to each group. Iterate through all the input documents and output one document for each different group. The output document contains only identifier columns and calculated columns, if specified.

$sort

Rearranges the document stream by the specified sort key. Only the order has changed; the document remains the same. For each input document, output one document.

$geoUear

Returns a sorted stream of documents based on adjacent geospatial points. For geospatial data, combine $match, $sort, and $limit functions. The output document contains an additional distance field and can contain a location identifier field.

$out

Write the result document of the aggregation pipeline to a collection. When using the $out phase, it must be the last stage in the pipeline.

Additional resources

MongoDB Analytics: Learn Aggregation by Example: Exploratory Analytics and Visualization Using Flight Data

MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregation Framework and Hadoop

The Aggregation Framework

Webinar: Exploring the Aggregation Framework

Quick Reference Cards

Tags: Document output input or pipe field phase array element identity identifier grouping function geography space expression sorting transformation different number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL NVidia OPPO Reno Docker