MongoDB Query Language (MQL) Aggregation Operators

Aggregation operators process and transform data within aggregation pipelines. These operators enable you to perform complex data manipulations, including grouping, filtering, reshaping, and computing derived values from your document collections.

$addFields

The $addFields stage in the aggregation pipeline is used to add new fields to documents.

$bucket

Groups input documents into buckets based on specified boundaries.

$changeStream

The $changeStream stage opens a change stream cursor to track data changes in real-time.

$collStats

The $collStats stage in the aggregation pipeline is used to return statistics about a collection.

$convert

The $convert operator converts an expression into the specified type

$densify

Adds missing data points in a sequence of values within an array or collection.

$documents

The $documents stage creates a pipeline from a set of provided documents.

$facet

The $facet allows for multiple parallel aggregations to be executed within a single pipeline stage.

$fill

The $fill stage allows filling missing values in documents based on specified methods and criteria.

$geoNear

The $geoNear operator finds and sorts documents by their proximity to a geospatial point, returning distance information for each document.

$group

The $group stage groups documents by specified identifier expressions and applies accumulator expressions.

$indexStats

The $indexStats stage returns usage statistics for each index in the collection.

$isNumber

The $isNumber operator checks if a specified expression is a numerical type

$lookup

The $lookup stage in the Aggregation Framework is used to perform left outer joins with other collections.

$match

The $match stage in the aggregation pipeline is used to filter documents that match a specified condition.

$merge

The $merge stage in an aggregation pipeline writes the results of the aggregation to a specified collection.

$out

The `$out` stage in an aggregation pipeline writes the resulting documents to a specified collection.

$redact

Filters the content of the documents based on access rights.

$replaceWith

The $replaceWith operator in DocumentDB returns a document after replacing a document with the specified document

$sample

The $sample operator in DocumentDB returns a randomly selected number of documents

$set

The $set operator in DocumentDB updates or creates a new field with a specified value

$skip

The $skip stage in the aggregation pipeline is used to skip a specified number of documents from the input and pass the remaining documents to the next stage in the pipeline.

$sort

The $sort stage in the aggregation pipeline is used to order the documents in the pipeline by a specified field or fields.

$sortByCount

The $sortByCount stage in the aggregation pipeline is used to group documents by a specified expression and then sort the count of documents in each group in descending order.

$toBool

The $toBool operator converts an expression into a Boolean type

$toDate

The $toDate operator converts supported types to a proper Date object.

$toDecimal

The $toDecimal operator converts an expression into a Decimal type

$toDouble

The $toDouble operator converts an expression into a Double value

$toInt

The $toInt operator converts an expression into an Integer

$toLong

The $toLong operator converts an expression into a Long value

$toObjectId

The $toObjectId operator converts an expression into an ObjectId

$toString

The $toString operator converts an expression into a String

$unset

The $unset stage in the aggregation pipeline is used to remove specified fields from documents.

$unwind

The $unwind stage in the aggregation framework is used to deconstruct an array field from the input documents to output a document for each element.