UpdatePipelineOperations¶
interface UpdatePipelineOperations<Document : Any> : BaseOperations
Interface grouping MongoDB operations allowing to update existing information using aggregation pipelines.
Inheritors¶
Properties¶
context¶
@LowLevelApi
abstract val context: BsonContext
Functions¶
updateManyWithPipeline¶
@IgnorableReturnValue
abstract fun updateManyWithPipeline(
options: UpdateOptions<Document>.() -> Unit = {},
filter: FilterQuery<Document>.() -> Unit = {},
update: UpdateWithPipelineQuery<Document>.() -> Unit
): UpdateOperations.UpdateResult
Updates all documents that match filter according to the update pipeline.
Example¶
class User(
val name: String,
val age: Int,
)
collection.updateManyWithPipeline(
filter = {
User::name eq "Patrick"
}
) {
set {
User::age set 15
}
}
External resources¶
Parameters
- filter: Optional filter to select which documents are updated. If no filter is specified, all documents are updated.
See also
UpdatePipelineOperations.updateOneWithPipeline: Update a single document.
updateOneWithPipeline¶
@IgnorableReturnValue
abstract fun updateOneWithPipeline(
options: UpdateOptions<Document>.() -> Unit = {},
filter: FilterQuery<Document>.() -> Unit = {},
update: UpdateWithPipelineQuery<Document>.() -> Unit
): UpdateOperations.UpdateResult
Updates a single document that matches filter according to the update pipeline.
If multiple documents match filter, only the first one found is updated.
Example¶
class User(
val name: String,
val age: Int,
)
collection.updateOneWithPipeline(
filter = {
User::name eq "Patrick"
}
) {
set {
User::age set 15
}
}
External resources¶
Parameters
- filter: Optional filter to select which document is updated. If no filter is specified, the first document found is updated.
See also
-
UpdatePipelineOperations.updateManyWithPipeline: Update multiple documents. -
UpdatePipelineOperations.upsertOneWithPipeline: Update a document, creating it if it doesn't exist.
upsertOneWithPipeline¶
@IgnorableReturnValue
abstract fun upsertOneWithPipeline(
options: UpdateOptions<Document>.() -> Unit = {},
filter: FilterQuery<Document>.() -> Unit = {},
update: UpdateWithPipelineQuery<Document>.() -> Unit
): UpdateOperations.UpsertResult
Updates a single document that matches filter according to the update pipeline.
If multiple documents match filter, only the first one is updated.
If no documents match filter, a new one is created.
Example¶
class User(
val name: String,
val age: Int,
)
collection.upsertOneWithPipeline(
filter = {
User::name eq "Patrick"
}
) {
set {
User::age set 15
}
}
External resources¶
See also
UpdatePipelineOperations.updateOneWithPipeline: Do nothing if the document doesn't already exist.