Skip to content

HasCount

Pipeline implementing the $count stage.

Inheritors

Properties

context

@LowLevelApi



abstract val context: BsonContext

The context used to generate this pipeline.

Functions

countTo

open fun <Output : Any> countTo(field: Field<Output, Number>): Pipeline<Output>

Counts how many elements exist in the pipeline and outputs a single document containing a single field containing the count.

field must be a simple field name. Subfields (accessed through the / operator) are forbidden.

Example
class Score(
    val student: ObjectId,
    val subject: String,
    val score: Int,
)

class Results(
    val passingScores: Int,
)

scores.aggregate()
    .match { Score::score gt 99 }
    .countTo(Results::passingScores)

Counts how many elements exist in the pipeline and outputs a single document containing a single field containing the count.

field must be a simple field name. Subfields (accessed through the / operator) are forbidden.

Example
class Score(
    val student: ObjectId,
    val subject: String,
    val score: Int,
)

class Results(
    val passingScores: Int,
)

scores.aggregate()
    .match { Score::score gt 99 }
    .countTo(Results::passingScores)

reinterpret

@DangerousMongoApi



@LowLevelApi



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

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

toString

abstract override fun toString(): String

JSON representation of this pipeline.

withStage

@DangerousMongoApi



@LowLevelApi



abstract fun withStage(stage: BsonNode): Pipeline<Document>

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

writeTo

@LowLevelApi



abstract fun writeTo(writer: BsonValueWriter)

Writes the entire pipeline into writer.