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:对于更新,管道可以由以下阶段组成:
$addFieldsand its alias及其别名$set$projectand its alias及其别名$unset$replaceRootand 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 |