mongoDB之Pipeline Aggregation Stages

原文链接:https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/

管道聚合

$project Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.

修改文件的输入或输出流,例如增加新的字段,或者删除已存在的字段。

 

$match  Filters 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).

过滤文件流,但不改变文件流中的字段。

 

$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.

The argument can be any valid expression as long as it resolves to $$DESCEND$$PRUNE, or $$KEEP system variables. For more information on expressions, see Expressions.

支持表达式方式的过滤,很重要的功能。

 

$limit  Passes 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).

限制传入到下一个阶段的字段个数。

 

$skip  Skips 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 ndocuments).

 

$unwind Deconstructs an array field from the input documents to output a document for eachelement. 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.

 对某个字段组进行分组,分成多个元素。

 

$group Groups 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.

根据group分组的表达形式,对于输入的字段进行处理,并规定的group的组的规则输出。

 

$sort  Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document.

 

$geoNear Returns 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.

 

$lookup Performs a left outer join to another collection in the same database to filter in documents from the “joined” collection for processing.

 

$out  Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline.

 

$indexStats Returns statistics regarding the use of each index for the collection.

 

转载于:https://www.cnblogs.com/passion-hzhang/p/6052423.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MongoDB的聚合管道(Aggregation Pipeline)是一种数据处理方法,通过一系列的阶段(stage)组成的管道对文档进行处理,并输出相应的结果。每个阶段可以进行分组、过滤等功能,可以方便地对数据进行处理。使用MongoDB内置的原生操作,聚合效率非常高,并支持类似于SQL Group By操作的功能。聚合管道的每个节点管道的内存限制为100MB,超过这个限制会产生错误。为了处理大型数据集,可以设置allowDiskUse为true,将数据写入临时文件以解决内存限制。聚合管道可以作用在分片集合,但结果不能输送到分片集合中。聚合管道的结果可以保存在一个文档中,BSON Document大小限制为16M,但可以通过返回指针解决。聚合管道的语法是db.collection.aggregate([ { <stage> }, ... ]),其中pipeline类型是数组。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [MongoDB聚合(Aggregation Pipeline基础篇上](https://blog.csdn.net/aaywod4483/article/details/101543707)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [学习MongoDB 十一: MongoDB聚合(Aggregation Pipeline基础篇上)(三)](https://blog.csdn.net/congcong68/article/details/51619882)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值