UpdateWithPipelineQuery¶
interface UpdateWithPipelineQuery<Document : Any> : CompoundBsonNode
Interface describing the DSL when declaring an update with a pipeline.
Constructors¶
UpdateWithPipelineQuery¶
@LowLevelApi
fun <T : Any> UpdateWithPipelineQuery(context: BsonContext): UpdateWithPipelineQuery<T>
Creates an empty UpdateWithPipelineQuery.
Properties¶
context¶
@LowLevelApi
abstract val context: BsonContext
The context used to generate this expression.
Functions¶
accept¶
Adds a new node as a child of this one.
acceptAll¶
Adds any number of nodes into this one.
freeze¶
@LowLevelApi
abstract override fun freeze()
Makes this expression immutable.
project¶
open fun project(block: ProjectStageOperators<Document>.() -> Unit)
Specify which fields should be kept.
This method is equivalent to the `$project stage`.
Difference with $set and $¶
unset
This 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
}
}
External resources¶
set¶
open fun set(block: SetStageOperators<Document>.() -> Unit)
Overrides the value of existing fields or inserts new ones.
This method is equivalent to the `$set stage`.
Example¶
class User(
val name: String,
val age: Int,
)
users.updateManyWithPipeline {
set {
User::age set 12
}
}
External resources¶
simplify¶
Returns a simplified (but equivalent) expression to the current expression.
toBson¶
Writes the result of simplifying to a new BSON document.
toString¶
JSON representation of this expression.
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)
}
}
External resources¶
writeTo¶
@LowLevelApi
abstract override fun writeTo(writer: BsonFieldWriter)
Writes the result of simplifying this expression into writer.