Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.aggregation.stagesProjectStageOperatorsinclude

include

abstract fun include(field: Field<Document, *>)

Explicitly includes field.

Note that fields that aren't mentioned in the $project stage are deleted (except the _id field, which must be explicitly excluded).

Example

class User(
   val name: String,
   val age: Int,
)

users.aggregate()
    .project {
        include(User::age)
    }

External resources

open fun include(field: KProperty1<Document, *>)

Explicitly includes field.

Note that fields that aren't mentioned in the $project stage are deleted (except the _id field, which must be explicitly excluded).

Example

class User(
   val name: String,
   val age: Int,
)

users.aggregate()
    .project {
        include(User::age)
    }

External resources