Aggregation Pipeline Stages聚合管道阶段
On this page本页内容
In the 在db.collection.aggregate()
method and db.aggregate()
method, pipeline stages appear in an array. db.collection.aggregate()
方法和db.aggregate()
方法中,管道阶段显示在数组中。Documents pass through the stages in sequence.文件按顺序通过各个阶段。
Stages阶段
db.collection.aggregate()
Stages阶段
All stages except the 除$out
, $merge
, $geoNear
, $changeStream
, and $changeStreamSplitLargeEvent
stages can appear multiple times in a pipeline.$out
、$merge
、$geoNear
、$changeStream
和$changeStreamSplitLargeEvent
阶段外的所有阶段都可以在管道中多次出现。
For details on a specific operator, including syntax and examples, click on the link to the operator's reference page.有关特定运算符的详细信息,包括语法和示例,请单击该运算符参考页的链接。
db.collection.aggregate( [ { <stage> }, ... ] )
$addFields | $project , $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.$project ,$addFields 对流中的每个文档进行重新整形;具体地说,通过将新字段添加到既包含输入文档中的现有字段又包含新添加字段的输出文档中。$set is an alias for $addFields . $set 是$addFields 的别名。 |
$bucket | |
$bucketAuto | |
$changeStream | |
$changeStreamSplitLargeEvent | $changeStreamSplitLargeEvent in a $changeStream pipeline and it must be the final stage in the pipeline. $changeStream 管道中使用$changeStreamSplitTargetEvent ,并且它必须是管道中的最后阶段。 |
$collStats | |
$count | $count aggregation accumulator. $count 聚合累加器不同。 |
$densify | |
$documents | |
$facet | |
$fill | null and missing field values within documents.null 字段值和缺少的字段值。 |
$geoNear | $match , $sort , and $limit for geospatial data. $match 、$sort 和$limit 功能。 |
$graphLookup | |
$group | |
$indexStats | |
$limit | |
$listSampledQueries | |
$listSearchIndexes | |
$listSessions | system.sessions collection.system.sessions 集合的所有会话。 |
$lookup | |
$match | $match uses standard MongoDB queries. $match 使用标准的MongoDB查询。 |
$merge | $merge stage, it must be the last stage in the pipeline. $merge 阶段,它必须是管道中的最后一个阶段。 |
$out | $out stage, it must be the last stage in the pipeline.$out 阶段,它必须是管道中的最后一个阶段。 |
$planCacheStats | |
$project | $unset for removing existing fields. $unset 以删除现有字段。 |
$redact | $project and $match . $project 和$match 的功能。 |
$replaceRoot | _id field. _id 字段。$replaceWith $replaceRoot stage. $replaceRoot 阶段的别名。 |
$replaceWith | _id field. _id 字段。$replaceWith $replaceRoot stage. $replaceRoot 阶段的别名。 |
$sample | |
$search | Note $search |
$searchMeta | Note $searchMeta |
$set | $project , $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.$project 类似,$set 对流中的每个文档进行重新整形;具体地说,通过将新字段添加到既包含输入文档中的现有字段又包含新添加字段的输出文档中。$set $addFields stage. $addFields 阶段的别名。 |
$setWindowFields | |
$skip | |
$sort | |
$sortByCount | |
$unionWith | |
$unset | $unset $project stage that removes fields. $project 阶段的别名。 |
$unwind |
For aggregation expression operators to use in the pipeline stages, see Aggregation Pipeline Stages.有关要在管道阶段中使用的聚合表达式运算符,请参阅聚合管道阶段。
db.aggregate()
Stages阶段
MongoDB also provides the MongoDB还提供了db.aggregate()
method:db.aggregate()
方法:
db.aggregate( [ { <stage> }, ... ] )
The following stages use the 以下阶段使用db.aggregate()
method and not the db.collection.aggregate()
method.db.aggregate()
方法,而不是使用db.collection.aggregate()
方法。
$changeStream | |
$currentOp | |
$listLocalSessions | mongos or mongod instance. mongos 或mongod 实例上使用的所有活动会话。system.sessions collection.system.sessions 集合。 |
$documents |
Stages Available for Updates可用于更新的阶段
Starting in MongoDB 4.2, you can use the aggregation pipeline for updates in:从MongoDB 4.2开始,您可以在以下位置使用聚合管道进行更新:
For the updates, the pipeline can consist of the following stages:对于更新,管道可以由以下阶段组成:
$addFields
and its alias及其别名$set
$project
and its alias及其别名$unset
$replaceRoot
and its alias及其别名$replaceWith
.
Alphabetical Listing of Stages阶段的字母列表
$addFields | |
$bucket | |
$bucketAuto | |
$changeStream | |
$changeStreamSplitLargeEvent | $changeStreamSplitLargeEvent in a $changeStream pipeline and it must be the final stage in the pipeline. $changeStream 管道中使用$changeStreamSplitTargetEvent ,并且它必须是管道中的最后阶段。 |
$collStats | |
$count | $count aggregation accumulator. $count 聚合累加器不同。 |
$currentOp | db.aggregate() method.db.aggregate() 方法。 |
$densify | |
$documents | |
$facet | |
$fill | null and missing field values within documents. |
$geoNear | $match , $sort , and $limit for geospatial data. $match 、$sort 和$limit 功能。 |
$graphLookup | |
$group | |
$indexStats | |
$limit | |
$listLocalSessions | mongos or mongod instance. mongos 或mongod 实例上使用的所有活动会话。system.sessions collection.system.sessions 集合。 |
$listSampledQueries | |
$listSearchIndexes | |
$listSessions | system.sessions collection.system.sessions 集合的所有会话。 |
$lookup | |
$match | $match |
$merge | $merge stage, it must be the last stage in the pipeline. $merge 阶段,它必须是管道中的最后一个阶段。 |
$out | $out stage, it must be the last stage in the pipeline.$out 阶段,它必须是管道中的最后一个阶段。 |
$planCacheStats | |
$project | |
$redact | $project and $match . $project 和$match 的功能。 |
$replaceRoot | _id field. _id 字段。 |
$replaceWith | _id field. _id 字段。$replaceRoot . $replaceRoot 的别名。 |
$sample | |
$search | Note $search |
$searchMeta | Note $searchMeta |
$set | Alias for $addFields . |
$setWindowFields | |
$shardedDataDistribution | |
$skip | |
$sort | |
$sortByCount | |
$unionWith | |
$unset | $project stage that removes or excludes fields. $project 阶段的别名,用于删除或排除字段。 |
$unwind |