project
Specify which fields should be kept.
This method is equivalent to the $project stage.
Difference with
$set and $
unsetThis stage is quite similar to $set and $unset:
Like
$set, this stage can override existing fields. However,$projectdeletes fields that aren't mentioned, whereas$setleaves them as-is.Like
$unset, this stage can delete fields. However,$projectexplicitly specifies the fields to keep, whereas$unsetexplicitly specifies the fields to remove.
Example
class User(
val name: String,
val age: Int,
val score: Int?,
)
users.updateManyWithPipeline {
project {
include(User::age)
User::score set 12
}
}Content copied to clipboard