Aggregation stages Flashcards

1
Q

$addFields

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

$bucket

A

Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

$bucketAuto

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

$changeStream

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

$collStats

A

Returns statistics regarding a collection or view.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

$count

A

Returns a count of the number of documents at this stage of the aggregation pipeline.

Distinct from the $count aggregation accumulator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

$currentOp

A

Returns information about current operations in MongoDB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

$densify

A

Creates new documents in a sequence of documents where certain values in a field are missing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

$documents

A

Returns literal documents from input expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

$facet

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

$fill

A

Populates null and missing field values within documents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

$geoNear

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

$graphLookup

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

$group

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

$indexStats

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

$limit

A

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

17
Q

$listLocalSessions

A

Lists the sessions in the current transaction.

18
Q

$listSessions

A

Lists all sessions that have been active long enough to propagate to the system.sessions collection.

19
Q

$lookup

A

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

20
Q

$match

A

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

21
Q

$merge

A

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.

22
Q

$out

A

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.

23
Q

$planCacheStats

A

Returns plan cache information for a collection.

24
Q

$project

A

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

25
Q

$redact

A

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.

26
Q

$replaceRoot

A

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

27
Q

$replaceWith

A

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

28
Q

$sample

A

Randomly selects the specified number of documents from its input.

29
Q

$set

A

Adds new fields to documents. Similar to $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.

$set is an alias for $addFields stage.

30
Q

$setWindowFields

A

Groups documents into windows and applies one or more operators to the documents in each window.

New in version 5.0.

31
Q

$shardedDataDistribution

A

Provides statistics on the distribution of data across shards.

32
Q

$skip

A

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 n documents).

33
Q

$sort

A

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

34
Q

$sortByCount

A

Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group.

35
Q

$unionWith

A

Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set.

New in version 4.4.

36
Q

$unset

A

Removes/excludes fields from documents.

$unset is an alias for $project stage that removes fields.

37
Q

$unwind

A

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