Pipeline

interface Pipeline<Output : Any>(source)

A multi-stage pipeline that performs complex operations on MongoDB.

Similar to Sequence and Flow, but executed by MongoDB itself.

MongoDB has different types of pipelines with different available operators, which are represented by the different implementations of this interface.

Instances of this class are immutable.

Stages

A pipeline is composed of stages, each of which transforms the data in some way. For example, some stages filter information out, some stages add more information, some stages combine documents, some stages extract information from elsewhere, etc.

Each stage is defined as an extension function on this class. Note that as mentioned, not all stages are available for all pipeline types. The following stages are available:

If you can't find a stage you're searching for, visit the tracking issue.

Implementing a new stage

Just like operators, stages can be added as extension methods on this type or any of its subtypes. To register the stage, call withStage, optionally followed by reinterpret, and return the resulting pipeline.

Stages should return Pipeline instances that were generated by the withStage or reinterpret methods. Pipeline implementations are allowed to assume all stages they will be provided were generated by their own implementation of these methods, and thus may downcast the resulting pipeline to another type safely. Returning any other Pipeline instance has unspecified behavior.

External resources

Parameters

Output

The type of document that this pipeline results in. Changing this type is possible by calling reinterpret.

Inheritors

Properties

Link copied to clipboard
abstract val context: <Error class: unknown class>

The context used to generate this pipeline.

Functions

Link copied to clipboard
abstract fun <New : Any> reinterpret(): Pipeline<New>

Changes the type of the returned document, with no type-safety.

Link copied to clipboard
abstract override fun toString(): String

JSON representation of this pipeline.

Link copied to clipboard
abstract fun withStage(stage: BsonNode): Pipeline<Output>

Creates a new pipeline that expands on the current one by adding stage.

Link copied to clipboard
abstract fun writeTo(writer: <Error class: unknown class>)

Writes the entire pipeline into writer.