BulkWrite

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

Constructors

Link copied to clipboard
constructor(context: <Error class: unknown class>, globalFilter: FilterQuery<Document>.() -> Unit)

Properties

Link copied to clipboard
abstract val context: <Error class: unknown class>

The context used to generate this expression.

Link copied to clipboard
val operations: <Error class: unknown class><AvailableInBulkWrite<Document>>
Link copied to clipboard

Functions

Link copied to clipboard
open override fun accept(node: AvailableInBulkWrite<Document>)

Adds a new Node into the current node.

Link copied to clipboard
fun <N : Node> CompoundNode<N>.acceptAll(nodes: Iterable<N>)

Adds any number of nodes into this one.

Link copied to clipboard
fun filtered(filter: FilterQuery<Document>.() -> Unit, operations: BulkWrite<Document>.() -> Unit)

Declares a filter that is shared between all children operations.

Link copied to clipboard
abstract override fun freeze()

Makes this expression immutable.

Link copied to clipboard
fun insertMany(vararg documents: Document, options: InsertOneOptions<Document>.() -> Unit = {})
fun insertMany(documents: Iterable<Document>, options: InsertOneOptions<Document>.() -> Unit = {})

Inserts multiple documents in a single operation.

Link copied to clipboard
fun insertOne(document: Document, options: InsertOneOptions<Document>.() -> Unit = {})

Inserts a document.

Link copied to clipboard
abstract fun simplify(): BsonNode?

Returns a simplified (but equivalent) expression to the current expression.

Link copied to clipboard
open fun toBson(): <Error class: unknown class>

Writes the result of simplifying to a new Bson.

Link copied to clipboard
fun toString(simplified: Boolean): String
abstract override fun toString(): String

JSON representation of this expression.

Link copied to clipboard
fun updateMany(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpdateQuery<Document>.() -> Unit)

Updates all documents that match filter according to update.

Link copied to clipboard
fun updateOne(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpdateQuery<Document>.() -> Unit)

Updates a single document that matches filter according to update.

Link copied to clipboard
fun upsertOne(options: UpdateOptions<Document>.() -> Unit = {}, filter: FilterQuery<Document>.() -> Unit = {}, update: UpsertQuery<Document>.() -> Unit)

Updates a single document that matches filter according to update.

Link copied to clipboard
abstract fun writeTo(writer: <Error class: unknown class>)

Writes the result of simplifying this expression into writer.