set

open fun <Out : Any> set(block: SetStageOperators<Document, Out>.() -> Unit): Pipeline<Out>(source)

Adds new fields to documents, or overwrites existing fields.

See $project to learn more about their differences.

Example

class User(
val _id: ObjectId,
val name: String,
val age: Int,
val isAdult: Boolean? = null,
)

users.aggregate()
.set {
User::isAdult set (User::age gte 18)
}

External resources

Parameters

block

The block defining the fields to set.