MongoDB request DSL • opensavvy.ktmongo.dsl.command • BulkWrite
BulkWrite¶
class BulkWrite<Document : Any> : AbstractBsonNode, Command, CompoundNode<AvailableInBulkWrite<Document>>
Performing multiple write operations in a single request.
Example¶
users.bulkWrite {
updateOne({ User::name eq "foo" }) {
User::age set 18
}
upsertOne({ User::name eq "bob" }) {
User::age setOnInsert 18
User::age inc 1
}
}
Filtered writes¶
If we have multiple writes that share a similar filter, we can extract it to be common between them.
users.bulkWrite {
updateOne({ User::name eq "foo" }) {
User::age set 18
}
filtered({ User::isAlive eq true }) {
updateMany({ User::name eq "bar" }) {
User::age inc 2
}
updateOne({ User::name eq "baz" }) {
User::age inc 1
}
}
}
To learn more, see filtered
.
External resources¶
See also¶
BulkWriteOptions
Options
Constructors¶
BulkWrite
¶
constructor(context: , globalFilter: FilterQuery<Document>.() -> Unit)
Properties¶
context
¶
abstract val context:
The context used to generate this expression.
operations
¶
val operations: <AvailableInBulkWrite<Document>>
options
¶
val options: BulkWriteOptions<Document>
Functions¶
accept
¶
open override fun accept(node: AvailableInBulkWrite<Document>)
Adds a new Node
into the current node.
acceptAll
¶
Adds any number of nodes
into this one.
filtered
¶
Declares a filter
that is shared between all children operations
.
freeze
¶
abstract override fun freeze()
Makes this expression immutable.
insertMany
¶
fun insertMany(vararg documents: Document, options: InsertOneOptions<Document>.() -> Unit = {})
Inserts multiple documents
in a single operation.
fun insertMany(documents: Iterable<Document>, options: InsertOneOptions<Document>.() -> Unit = {})
Inserts multiple documents
in a single operation.
insertOne
¶
fun insertOne(document: Document, options: InsertOneOptions<Document>.() -> Unit = {})
Inserts a document
.
simplify
¶
Returns a simplified (but equivalent) expression to the current expression.
toBson
¶
open fun toBson():
Writes the result of simplifying
to a new Bson.
toString
¶
JSON representation of this expression.
JSON representation of this expression.
updateMany
¶
fun updateMany(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpdateQuery<Document>.() -> Unit)
updateOne
¶
fun updateOne(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpdateQuery<Document>.() -> Unit)
upsertOne
¶
fun upsertOne(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpsertQuery<Document>.() -> Unit)
writeTo
¶
abstract fun writeTo(writer: )
Writes the result of simplifying
this expression into writer
.