set
Replaces the value of a field with the specified value.
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)
}Content copied to clipboard
If you want to create a temporary field that is only used within the aggregation and not deserialized, see Field.unsafe.
External resources
Replaces the value of an array with the specified list of values.
Example
class User(
val _id: ObjectId,
val name: String,
val age: Int,
val maths: Score,
val physics: Score,
val scores: List<Score>,
)
class Score(
val subject: String,
val value: Double,
val max: Double,
)
users.aggregate()
.set {
User::scores set listOf(
of(User::maths),
of(User::physics),
)
}Content copied to clipboard