AggregationPipeline

An aggregation pipeline.

Aggregation pipelines read data from one or more collections and transform it in a manner of ways. Finally, the data can be sent to the server, or written to another collection.

Example

invoices.aggregate()
.match { Invoice::isDraft eq false }
.set {
Invoice::anomaly set (of(Invoice::modificationDate) lt of(Invoice::creationDate))
}
.sort { ascending(Invoice::creationDate) }
.toList()

External resources

Properties

Link copied to clipboard

The context used to generate this pipeline.

Functions

Link copied to clipboard
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.

Link copied to clipboard

Writes this pipeline's contribution into a $lookup stage.

Link copied to clipboard

Writes this pipeline into a $unionWith stage.

Link copied to clipboard
open fun <Out : Any> group(block: GroupStageOperators<Document, Out>.() -> Unit): Pipeline<Out>

Combines many documents into few documents.

Link copied to clipboard
open fun limit(amount: Int): Pipeline<Document>
open fun limit(amount: Long): Pipeline<Document>

Limits the number of elements passed to the next stage to amount.

Link copied to clipboard

Performs an equality match join between this collection and another collection.

Link copied to clipboard
open fun match(filter: FilterQuery<Document>.() -> Unit): Pipeline<Document>

Filters documents based on a specified filter.

Link copied to clipboard

Filters documents based on a specific filter, written using aggregation syntax.

Link copied to clipboard

Specifies a list of fields which should be kept in the document.

Link copied to clipboard

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

Link copied to clipboard
open fun sample(size: Int): Pipeline<Document>

Randomly selects size documents.

Link copied to clipboard

Adds new fields to documents, or overwrites existing fields.

Link copied to clipboard
open fun skip(amount: Int): Pipeline<Document>
open fun skip(amount: Long): Pipeline<Document>

Skips over the specified amount of documents that pass into the stage, and passes the remaining documents to the next stage.

Link copied to clipboard
open fun sort(block: SortOptionDsl<Document>.() -> Unit): Pipeline<Document>

Specifies in which order elements should be sorted.

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

JSON representation of this pipeline.

Link copied to clipboard

Combines two aggregations into a single result set.

Link copied to clipboard

Removes fields from documents.

Link copied to clipboard

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

Link copied to clipboard
abstract fun writeTo(writer: BsonValueWriter)

Writes the entire pipeline into writer.