Aggregation stages Flashcards
(37 cards)
$addFields
Adds new fields to documents. Similar to $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.
$set is an alias for $addFields.
$bucket
Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.
$bucketAuto
Categorizes 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.
$changeStream
Returns a Change Stream cursor for the collection. This stage can only occur once in an aggregation pipeline and it must occur as the first stage.
$collStats
Returns statistics regarding a collection or view.
$count
Returns a count of the number of documents at this stage of the aggregation pipeline.
Distinct from the $count aggregation accumulator.
$currentOp
Returns information about current operations in MongoDB.
$densify
Creates new documents in a sequence of documents where certain values in a field are missing.
$documents
Returns literal documents from input expressions.
$facet
Processes 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.
$fill
Populates null and missing field values within documents.
$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.
$graphLookup
Performs 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.
$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.
$indexStats
Returns statistics regarding the use of each index for the collection.
$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).
$listLocalSessions
Lists the sessions in the current transaction.
$listSessions
Lists all sessions that have been active long enough to propagate to the system.sessions collection.
$lookup
Performs a left outer join to another collection in the same database to filter in documents from the “joined” collection for processing.
$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).
$merge
Writes 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.
$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.
$planCacheStats
Returns plan cache information for a collection.
$project
Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document.
See also $unset for removing existing fields