MongoDB request DSL • opensavvy.ktmongo.dsl.query • UpdateWithPipelineQuery • unset
unset¶
open fun unset(block: UnsetStageOperators<Document>.() -> Unit)
Deletes existing fields.
This method is equivalent to the `$unset stage`.
Example¶
class User(
val name: String,
val age: Int,
val oldValue: String,
)
users.updateManyWithPipeline {
unset {
exclude(User::age)
}
}
External resources¶
open fun unset(vararg properties: KProperty1<Document, *>)
Deletes existing fields.
This method is equivalent to the `$unset stage`.
Example¶
class User(
val name: String,
val age: Int,
val oldValue: String,
)
users.updateManyWithPipeline {
unset(User::age, User::oldValue)
}
Properties and fields¶
Although this method can accept a vararg, it can only accept top-level properties. An overload exists that accepts Field instances. If you need to mix top-level properties and fields, use the overload that accepts a lambda, or use FieldDsl.field to convert properties to fields.
For example:
class Profile(
val name: String,
)
class User(
val profile: Profile,
val age: Int,
)
users.updateManyWithPipeline {
unset(User::age.field, User::profile / Profile::name)
}
or
users.updateManyWithPipeline {
unset {
exclude(User::age)
exclude(User::profile / Profile::name)
}
}
External resources¶
Deletes existing fields.
This method is equivalent to the `$unset stage`.
Example¶
class User(
val name: String,
val age: Int,
val oldValue: String,
)
users.updateManyWithPipeline {
unset(User::age, User::oldValue)
}
Properties and fields¶
Although this method can accept a vararg, it cannot accept top-level properties. An overload exists that accepts KProperty1 instances. If you need to mix top-level properties and fields, use the overload that accepts a lambda, or use FieldDsl.field to convert properties to fields.
For example:
class Profile(
val name: String,
)
class User(
val profile: Profile,
val age: Int,
)
users.updateManyWithPipeline {
unset(User::age.field, User::profile / Profile::name)
}
or
users.updateManyWithPipeline {
unset {
exclude(User::age)
exclude(User::profile / Profile::name)
}
}