MongoDB Aggregation Pipeline Stages

StageDescription
$addFieldsAdds new fields to documents. Similar to $project, a d d F i e l d s r e s h a p e s e a c h d o c u m e n t i n t h e s t r e a m ; s p e c i f i c a l l y , b y a d d i n g n e w f i e l d s t o o u t p u t d o c u m e n t s t h a t c o n t a i n b o t h t h e e x i s t i n g f i e l d s f r o m t h e i n p u t d o c u m e n t s a n d t h e n e w l y a d d e d f i e l d s . addFields reshapes each document in the stream; specifically, by adding new fields to output documents that contain both the existing fields from the input documents and the newly added fields. addFieldsreshapeseachdocumentinthestream;specifically,byaddingnewfieldstooutputdocumentsthatcontainboththeexistingfieldsfromtheinputdocumentsandthenewlyaddedfields.set is an alias for $addFields.
$bucketCategorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.
$bucketAutoCategorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets.
$collStatsReturns statistics regarding a collection or view.
$countReturns a count of the number of documents at this stage of the aggregation pipeline.
$facetProcesses multiple aggregation pipelines within a single stage on the same set of input documents. Enables the creation of multi-faceted aggregations capable of characterizing data across multiple dimensions, or facets, in a single stage.
$geoNearReturns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of $match, $sort, and $limit for geospatial data. The output documents include an additional distance field and can include a location identifier field.
$graphLookupPerforms a recursive search on a collection. To each output document, adds a new array field that contains the traversal results of the recursive search for that document.
$groupGroups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields.
$indexStatsReturns statistics regarding the use of each index for the collection.
$limitPasses the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents).
$listSessionsLists all sessions that have been active long enough to propagate to the system.sessions collection.
$lookupPerforms a left outer join to another collection in the same database to filter in documents from the “joined” collection for processing.
$matchFilters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match).
$mergeWrites the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the $merge stage, it must be the last stage in the pipeline.New in version 4.2.
$outWrites the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline.
$planCacheStatsReturns plan cache information for a collection.
$projectReshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.
$redact Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of $project and $match. Can be used to implement field level redaction. For each input document, outputs either one or zero documents.
$replaceRootReplaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level.$replaceWith is an alias for $replaceRoot stage.
$replaceWithReplaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level.$replaceWith is an alias for $replaceRoot stage.
$sampleRandomly selects the specified number of documents from its input.
$setAdds new fields to documents. Similar to $project, s e t r e s h a p e s e a c h d o c u m e n t i n t h e s t r e a m ; s p e c i f i c a l l y , b y a d d i n g n e w f i e l d s t o o u t p u t d o c u m e n t s t h a t c o n t a i n b o t h t h e e x i s t i n g f i e l d s f r o m t h e i n p u t d o c u m e n t s a n d t h e n e w l y a d d e d f i e l d s . set reshapes each document in the stream; specifically, by adding new fields to output documents that contain both the existing fields from the input documents and the newly added fields. setreshapeseachdocumentinthestream;specifically,byaddingnewfieldstooutputdocumentsthatcontainboththeexistingfieldsfromtheinputdocumentsandthenewlyaddedfields.set is an alias for $addFields stage.
$skipSkips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents).
$sortReorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document.
$sortByCountGroups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.
$unsetRemoves/excludes fields from documents.$unset is an alias for $project stage that removes fields.
$unwindDeconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array.

参考:
https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值