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,$project
deletes fields that aren't mentioned, whereas$set
leaves them as-is.Like
$unset
, this stage can delete fields. However,$project
explicitly specifies the fields to keep, whereas$unset
explicitly 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