UpdateQuery

DSL for MongoDB operators that are used to update existing values (does not include aggregation operators).

Example

This expression type is available on multiple operations, most commonly update:

class User(
val name: String,
val age: Int,
)

collection.update(
filter = {
User::name eq "Bob"
},
update = {
User::age set 18
}
)

Operators

On regular fields:

On arrays:

Time management:

If you can't find the operator you're searching for, visit the tracking issue.

External resources

See also

Inheritors

Properties

Link copied to clipboard
open val <E> KProperty1<T, Collection<E>>.all: Field<T, E>
open val <E> Field<T, Collection<E>>.all: Field<T, E>

The all positional operator: selects all elements of an array.

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

The context used to generate this expression.

Link copied to clipboard

Converts a Kotlin property into a Field.

Link copied to clipboard
open val <E> Field<T, Collection<E>>.selected: Field<T, E>

The positional operator: update an array item selected in the filter.

Functions

Link copied to clipboard
abstract override fun accept(node: BsonNode)

Adds a new node as a child of this one.

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
open infix fun <V> KProperty1<T, Collection<V>>.addToSet(value: V)
abstract infix fun <V> Field<T, Collection<V>>.addToSet(value: V)

Adds value at the end of the array, unless it is already present, in which case it does nothing.

open infix fun <V> KProperty1<T, Collection<V>>.addToSet(values: Iterable<V>)
open infix fun <V> Field<T, Collection<V>>.addToSet(values: Iterable<V>)

Adds multiple values at the end of the array, unless they are already present.

Link copied to clipboard
open operator fun <Root, Parent, Child> KProperty1<Root, Parent>.div(child: KProperty1<Parent & Any, Child>): Field<Root, Child>

Refers to child as a nested field of the current field.

Link copied to clipboard
abstract override fun freeze()

Makes this expression immutable.

Link copied to clipboard
open operator fun <Root, Type> KProperty1<Root, Collection<Type>>.get(index: Int): Field<Root, Type>

Refers to a specific item in an array, by its index.

open operator fun <Root, Type> KProperty1<Root, Map<String, Type>>.get(index: String): Field<Root, Type>

Refers to a specific item in a map, by its name.

Link copied to clipboard
open infix fun <V : Number> KProperty1<T, V>.inc(amount: V)
abstract infix fun <V : Number> Field<T, V>.inc(amount: V)

Increments a field by the specified amount.

Link copied to clipboard
open infix fun <V : Comparable<V>> KProperty1<T, V?>.max(value: V)
abstract infix fun <V : Comparable<V>> Field<T, V?>.max(value: V)

Updates the value of a field to the specified value only if the specified value is greater than the current value of the field.

Link copied to clipboard
open infix fun <V : Comparable<V>> KProperty1<T, V?>.min(value: V)
abstract infix fun <V : Comparable<V>> Field<T, V?>.min(value: V)

Updates the value of a field to the specified value only if the specified value is less than the current value of the field.

Link copied to clipboard
open infix fun <V : Number> KProperty1<T, V>.mul(amount: V)
abstract infix fun <V : Number> Field<T, V>.mul(amount: V)

Multiplies a field by the specified amount.

Link copied to clipboard
open operator fun <V : Number> KProperty1<T, V>.plusAssign(amount: V)
open operator fun <V : Number> Field<T, V>.plusAssign(amount: V)

Increments a field by the specified amount.

Link copied to clipboard
open infix fun <V> KProperty1<T, V>.renameTo(newName: KProperty1<T, V>)
open infix fun <V> KProperty1<T, V>.renameTo(newName: Field<T, V>)
open infix fun <V> Field<T, V>.renameTo(newName: KProperty1<T, V>)
abstract infix fun <V> Field<T, V>.renameTo(newName: Field<T, V>)

Renames a field.

Link copied to clipboard
open infix fun <V> KProperty1<T, V>.set(value: V)
abstract infix fun <V> Field<T, V>.set(value: V)

Replaces the value of a field with the specified value.

Link copied to clipboard
open fun <V> KProperty1<T, V>.setIf(condition: Boolean, value: V)
open fun <V> Field<T, V>.setIf(condition: Boolean, value: V)

Replaces the value of a field with the specified value, if condition is true.

Link copied to clipboard
open fun KProperty1<T, <Error class: unknown class>?>.setToCurrentDate()
abstract fun Field<T, <Error class: unknown class>?>.setToCurrentDate()

Sets this field to the current date.

open fun KProperty1<T, <Error class: unknown class>?>.setToCurrentDate()
abstract fun Field<T, <Error class: unknown class>?>.setToCurrentDate()

Sets this field to the current timestamp.

Link copied to clipboard
open fun <V> KProperty1<T, V>.setUnless(condition: Boolean, value: V)
open fun <V> Field<T, V>.setUnless(condition: Boolean, value: V)

Replaces the value of a field with the specified value, if condition is false.

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
abstract override fun toString(): String

JSON representation of this expression.

Link copied to clipboard
open fun <V> KProperty1<T, V>.unset()
abstract fun <V> Field<T, V>.unset()

Deletes a field.

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

Writes the result of simplifying this expression into writer.