Skip to content

HasUnset

Pipeline implementing the $unset stage.

Inheritors

Properties

context

The context used to generate this pipeline.

Functions

reinterpret

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

toString

abstract override fun toString(): String

JSON representation of this pipeline.

unset

Removes fields from documents.

Example

We can use this stage to migrate from a schema to a newer schema.

class User(
    val name: String,
    val age: Int?,       // deprecated
    val birthYear: Int?, // new field
)

val currentYear = 2025
users.updateManyWithPipeline {
    set {
        User::birthYear set (of(currentYear) - of(age))
    }
    unset {
        exclude(User::age)
    }
}

External resources

withStage

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.