Skip to content

AbstractPipeline

abstract class AbstractPipeline<Output : Any>(val context: BsonContext, val chain: PipelineChainLink) : Pipeline<Output> 

Helper class to implement Pipeline.

Notes for implementors

When implementing a new type of pipeline, the main requirement is to override the return tpe of all existing stage methods to return the same type as the current instance. This sadly has to be done manually because Kotlin doesn't have self-types.

When overriding the stage methods, avoid doing anything other than down-casting the resulting pipeline.

You will also need to implement withStage. Note how creating an instance of AbstractPipeline requires passing a PipelineChainLink. PipelineChainLink implements all complex methods from Pipeline for you.

Constructors

AbstractPipeline

constructor(context: BsonContext, chain: PipelineChainLink)

Properties

chain

@LowLevelApi



val chain: PipelineChainLink

Internal representation of the pipeline state.

context

@LowLevelApi



open override val context: BsonContext

The context used to generate this pipeline.

Can be accessed within children expressions.

Functions

reinterpret

@DangerousMongoApi



@LowLevelApi



abstract fun <New : Any> reinterpret(): Pipeline<New>

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

End-users should not need to call this function. This function is provided to allow stages to change the return document. No type verifications are made, it is solely the responsibility of the caller to ensure that the declared return type corresponds to the reality.

See also

toString

override fun toString(): String

JSON representation of this pipeline.

withStage

@DangerousMongoApi



@LowLevelApi



abstract override fun withStage(stage: BsonNode): Pipeline<Output>

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

For usage documentation, see Pipeline.withStage.

Notes for implementors

A typical pipeline implementation will look like:

class YourPipelineType<Output : Any>(
    context: BsonContext,
    chain: PipelineChainLink,
): AbstractPipeline<Output>(context, chain) {
    // …

    override fun withStage(stage: Expression): YourPipelineType<Output> =
        YourPipelineType(context, chain.withStage(expression))

    // …
}

writeTo

@LowLevelApi



override fun writeTo(writer: BsonValueWriter)

Writes the entire pipeline into writer.

This function is similar to BsonNode.writeTo, with the difference that expressions generate documents, and pipelines generate arrays.

Using this method will thus write an array containing the different stages.