Skip to content

AccumulationOperators

DSL to accumulate values into each other, available in the `$group stage`.

Accumulation operators are a specific type of aggregation operators.

Operators

Arithmetic operators:

See also

Properties

context

@LowLevelApi



abstract override val context: BsonContext

The strategy used when converting from KProperty1 to Field.

field

Converts a Kotlin property into a Field.

isArray

open val <R : Any> Value<R, *>.isArray: Value<R, Boolean>

Determines if this value is an array.

isNumber

open val <R : Any> Value<R, *>.isNumber: Value<R, Boolean>

Determines if this value is a number.

length

Returns the number of code points in the specified string.

lengthUTF8

Returns the number of UTF-8 encoded bytes in the specified string.

type

open val <R : Any> Value<R, *>.type: Value<R, BsonType>

Gets the BsonType of the current value.

Functions

abs

open fun <Context : Any, Result : Number?> abs(value: Value<Context, Result>): Value<Context, Result>

The absolute value of a number.

accept

@LowLevelApi



@DangerousMongoApi



abstract override fun accept(node: BsonNode)

Adds a new node as a child of this one.

acceptAll

@LowLevelApi



@DangerousMongoApi



fun <N : Node> CompoundNode<N>.acceptAll(nodes: Iterable<N>)

Adds any number of nodes into this one.

acos

open fun <Context : Any> acos(value: Value<Context, Double?>): Value<Context, Double?>

The inverse cosine (arc cosine) of a value, in radians.

acosh

open fun <Context : Any> acosh(value: Value<Context, Double?>): Value<Context, Double?>

The inverse hyperbolic cosine (hyperbolic arc cosine) of a value, in radians.

asin

open fun <Context : Any> asin(value: Value<Context, Double?>): Value<Context, Double?>

The inverse sine (arc sine) of a value, in radians.

asinh

open fun <Context : Any> asinh(value: Value<Context, Double?>): Value<Context, Double?>

The inverse hyperbolic sine (hyperbolic arc sine) of a value, in radians.

atan

open fun <Context : Any> atan(value: Value<Context, Double?>): Value<Context, Double?>

The inverse tangent (arc tangent) of a value, in radians.

atanh

open fun <Context : Any> atanh(value: Value<Context, Double?>): Value<Context, Double?>

The inverse hyperbolic tangent (hyperbolic arc tangent) of a value, in radians.

average

open infix fun <T : Number> KProperty1<Into, T>.average(value: Value<From, Number?>)

Calculates and returns the collective average of numeric values. Non-numeric values are ignored.

open infix fun <T : Number> Field<Into, T>.average(value: Value<From, Number?>)

Calculates and returns the collective average of numeric values. Non-numeric values are ignored.

open fun <Context : Any, T : Number> average(): Value<Context, T>

Returns the average of the elements in the array.

Returns the average of the elements in the array.

Returns the average of the elements in the array.

Returns the average of the elements in the array.

open fun <Context : Any, T : Number> average(vararg input: Value<Context, Number?>): Value<Context, T>

Returns the average of the elements in the array.

ceil

open fun <Context : Any, Result : Number?> ceil(value: Value<Context, Result>): Value<Context, Result>

The smallest integer greater than or equal to the specified value.

concat

open fun <Context : Any> concat(strings: List<Value<Context, String?>>): Value<Context, String?>

Concatenates strings together.

open fun <Context : Any> concat(vararg strings: Value<Context, String?>): Value<Context, String?>

Concatenates strings together.

open infix fun <Context : Any> Value<Context, String?>.concat(other: Value<Context, String?>): Value<Context, String?>

Concatenates strings together.

cond

open fun <R : Any, T> cond(
    condition: Value<R, Boolean>, 
    ifTrue: Value<R, T>, 
    ifFalse: Value<R, T>
): Value<R, T>

Decides between two values depending on the evaluation of a boolean value.

cos

open fun <Context : Any> cos(value: Value<Context, Double?>): Value<Context, Double?>

The cosine of a value that is measured in radians.

cosh

open fun <Context : Any> cosh(value: Value<Context, Double?>): Value<Context, Double?>

The hyperbolic cosine of a value that is measured in radians.

div

open operator fun <Context : Any, Result> Value<Context, Result>.div(other: Value<Context, Result>): Value<Context, Result>

Divides one aggregation value by another.

open operator fun <Context : Any, Root, Child> Value<Context, Root>.div(field: KProperty1<Root, Child>): Value<Context, Child>

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

open operator fun <Context : Any, Root, Child> Value<Context, Root>.div(field: Field<Root, Child>): Value<Context, Child>

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

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.

open operator fun <Root, Type, Child> Field<Root, Type>.div(child: KProperty1<in Type & Any, Child>): Field<Root, Child>

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

open operator fun <Root, Type, Child> Field<Root, Type>.div(child: Field<Type, Child>): Field<Root, Child>

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

eq

open infix fun <Context : Any, Result> Value<Context, Result>.eq(other: Value<Context, Result>): Value<Context, Boolean>

Compares two aggregation values and returns true if they are equivalent.

filter

open fun <Context : Any, T> Collection<T>.filter(
    limit: Value<Context, Number>? = null, 
    variableName: String = "this", 
    predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>

Selects a subset of an array to return based on the specified predicate, similarly to Kotlin'sfilter``.

open fun <Context : Any, T> KProperty1<Context, Collection<T>>.filter(
    limit: Value<Context, Number>? = null, 
    variableName: String = "this", 
    predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>

Selects a subset of an array to return based on the specified predicate, similarly to Kotlin'sfilter``.

open fun <Context : Any, T> Value<Context, Collection<T>>.filter(
    limit: Value<Context, Number>? = null, 
    variableName: String = "this", 
    predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>

Selects a subset of an array to return based on the specified predicate, similarly to Kotlin'sfilter``.

open fun <Context : Any, T> Field<Context, Collection<T>>.filter(
    limit: Value<Context, Number>? = null, 
    variableName: String = "this", 
    predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>

Selects a subset of an array to return based on the specified predicate, similarly to Kotlin'sfilter``.

floor

open fun <Context : Any, Result : Number?> floor(value: Value<Context, Result>): Value<Context, Result>

The largest integer less than or equal to the specified value.

freeze

@LowLevelApi



abstract override fun freeze()

Makes this expression immutable.

get

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.

open operator fun <Root, Type> Field<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> Field<Root, Map<String, Type>>.get(key: String): Field<Root, Type>

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

gt

open infix fun <Context : Any, Result> Value<Context, Result>.gt(other: Value<Context, Result>): Value<Context, Boolean>

gte

lowercase

Converts a string to lowercase, returning the result.

lt

open infix fun <Context : Any, Result> Value<Context, Result>.lt(other: Value<Context, Result>): Value<Context, Boolean>

lte

map

open fun <Context : Any, T, R> Collection<T>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

open fun <Context : Any, T, R> KProperty1<Context, Collection<T>>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

open fun <Context : Any, T, R> Value<Context, Collection<T>>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

open fun <Context : Any, T, R> Field<Context, Collection<T>>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

median

open infix fun <T : Number> KProperty1<Into, T>.median(value: Value<From, Number?>)

Returns an approximation of the median, the 50th percentile, as a scalar value.

open infix fun <T : Number> Field<Into, T>.median(value: Value<From, Number?>)

Returns an approximation of the median, the 50th percentile, as a scalar value.

minus

open operator fun <Context : Any, Result> Value<Context, Result>.minus(other: Value<Context, Result>): Value<Context, Result>

Subtracts one aggregation value from another.

ne

open infix fun <Context : Any, Result> Value<Context, Result>.ne(other: Value<Context, Result>): Value<Context, Boolean>

Compares two aggregation values and returns true if they are not equivalent.

of

open fun <Result> of(value: Result): Value<Any, Result>

Refers to a Kotlin value within an aggregation value.

Refers to a field within an aggregation value.

open fun of(value: BsonType): Value<Any, BsonType>

Refers to a BsonType within an aggregation value.

open fun <Context : Any, Result> of(field: Field<Context, Result>): Value<Context, Result>

Refers to a field within an aggregation value.

percentiles

open fun <T : Number> KProperty1<Into, List<T>>.percentiles(value: Value<From, Number?>, vararg percentiles: Double)

Returns an approximation of the specified percentiles.

open fun <T : Number> Field<Into, List<T>>.percentiles(value: Value<From, Number?>, vararg percentiles: Double)

Returns an approximation of the specified percentiles.

plus

open operator fun <Context : Any, Result> Value<Context, Result>.plus(other: Value<Context, Result>): Value<Context, Result>

Sums two aggregation values.

replace

open fun <Context : Any> Value<Context, String?>.replace(find: String, replacement: String): Value<Context, String?>

Replaces all instances of find with a replacement string.

open fun <Context : Any> Value<Context, String?>.replace(find: Value<Context, String?>, replacement: Value<Context, String?>): Value<Context, String?>

Replaces all instances of find with a replacement string.

replaceFirst

open fun <Context : Any> Value<Context, String?>.replaceFirst(find: String, replacement: String): Value<Context, String?>

Replaces the first instance of find with a replacement string.

open fun <Context : Any> Value<Context, String?>.replaceFirst(find: Value<Context, String?>, replacement: Value<Context, String?>): Value<Context, String?>

Replaces the first instance of find with a replacement string.

simplify

@LowLevelApi



abstract fun simplify(): BsonNode?

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

sin

open fun <Context : Any> sin(value: Value<Context, Double?>): Value<Context, Double?>

The sine of a value that is measured in radians.

sinh

open fun <Context : Any> sinh(value: Value<Context, Double?>): Value<Context, Double?>

The hyperbolic sine of a value that is measured in radians.

sorted

open fun <Context : Any, T> Collection<T>.sorted(): Value<Context, List<T>>

Sorts an array based on its elements, in ascending order.

Sorts an array based on its elements, in ascending order.

Sorts an array based on its elements, in ascending order.

Sorts an array based on its elements, in ascending order.

sortedBy

open fun <Context : Any, T> Collection<T>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>

Sorts an array based on fields of its elements.

Sorts an array based on fields of its elements.

open fun <Context : Any, T> Value<Context, Collection<T>>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>

Sorts an array based on fields of its elements.

open fun <Context : Any, T> Field<Context, Collection<T>>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>

Sorts an array based on fields of its elements.

sortedDescending

Sorts an array based on its elements, in descending order.

Sorts an array based on its elements, in descending order.

Sorts an array based on its elements, in descending order.

Sorts an array based on its elements, in descending order.

split

open fun <Context : Any> Value<Context, String>.split(delimiter: String): Value<Context, List<String>?>

Divides a string into an array of substrings based on a delimiter.

Divides a string into an array of substrings based on a delimiter.

substring

Returns the substring of a string.

open fun <Context : Any> Value<Context, String?>.substring(startIndex: Value<Context, Int>, length: Value<Context, Int>): Value<Context, String?>

Returns the substring of a string.

substringUTF8

Returns the substring of a string.

open fun <Context : Any> Value<Context, String?>.substringUTF8(startIndex: Value<Context, Int>, byteCount: Value<Context, Int>): Value<Context, String?>

Returns the substring of a string.

sum

open infix fun <T : Number> KProperty1<Into, T>.sum(value: Value<From, Number?>)

Calculates and returns the collective sum of numeric values. Non-numeric values are ignored.

open infix fun <T : Number> Field<Into, T>.sum(value: Value<From, Number?>)

Calculates and returns the collective sum of numeric values. Non-numeric values are ignored.

switch

open fun <R : Any, T> switch(vararg cases: Pair<Value<R, Boolean>, Value<R, T>>, default: Value<R, T>? = null): Value<R, T>

Selects one value based on multiple conditions.

take

open fun <Context : Any, T> Collection<T>.take(limit: Value<Context, Number>): Value<Context, List<T>>

Returns the first limit elements in an array, similar to kotlin.collections.take.

Returns the first limit elements in an array, similar to kotlin.collections.take.

Returns the first limit elements in an array, similar to kotlin.collections.take.

Returns the first limit elements in an array, similar to kotlin.collections.take.

takeLast

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

tan

open fun <Context : Any> tan(value: Value<Context, Double?>): Value<Context, Double?>

The tangent of a value that is measured in radians.

tanh

open fun <Context : Any> tanh(value: Value<Context, Double?>): Value<Context, Double?>

The hyperbolic tangent of a value that is measured in radians.

times

open operator fun <Context : Any, Result> Value<Context, Result>.times(other: Value<Context, Result>): Value<Context, Result>

Multiplies two or more aggregation values.

toBoolean

open fun <R : Any> Value<R, *>.toBoolean(): Value<R, Boolean>

Converts this value to a BsonType.Boolean.

toBson

@LowLevelApi



open fun toBson(): Bson

Writes the result of simplifying to a new BSON document.

toDegrees

Converts an angle in radians to an angle in degrees.

toDouble

open fun <R : Any> Value<R, *>.toDouble(): Value<R, Double>

Converts this value to a BsonType.Double.

toInstant

open fun <R : Any> Value<R, *>.toInstant(): Value<R, Instant>

Converts this value to an Instant (BsonType.Datetime).

toInt

open fun <R : Any> Value<R, *>.toInt(): Value<R, Int>

Converts this value to an Int (BsonType.Int32).

toLong

open fun <R : Any> Value<R, *>.toLong(): Value<R, Long>

Converts this value to an Long (BsonType.Int64).

toObjectId

open fun <R : Any> Value<R, *>.toObjectId(): Value<R, ObjectId>

Converts this value to an ObjectId.

toRadians

Converts an angle in degrees to an angle in radians.

toText

open fun <R : Any> Value<R, *>.toText(): Value<R, String>

Converts this value to a String.

toUuid

@ExperimentalUuidApi
open fun <R : Any> Value<R, *>.toUuid(): Value<R, Uuid>

Converts a string value to a Uuid (BsonType.BinaryData).

trim

Removes whitespace characters, including null, or the specified characters from the beginning and end of a string.

open fun <Context : Any> Value<Context, String?>.trim(vararg characters: Char): Value<Context, String?>

Removes the specified characters from the beginning and end of a string.

open fun <Context : Any> Value<Context, String?>.trim(characters: Value<Context, String?>): Value<Context, String?>

Removes the specified characters from the beginning and end of a string.

trimEnd

Removes whitespace characters, including null, or the specified characters from the end of a string.

open fun <Context : Any> Value<Context, String?>.trimEnd(vararg characters: Char): Value<Context, String?>

Removes the specified characters from the end of a string.

open fun <Context : Any> Value<Context, String?>.trimEnd(characters: Value<Context, String?>): Value<Context, String?>

Removes the specified characters from the end of a string.

trimStart

Removes whitespace characters, including null, or the specified characters from the beginning of a string.

open fun <Context : Any> Value<Context, String?>.trimStart(vararg characters: Char): Value<Context, String?>

Removes the specified characters from the beginning of a string.

open fun <Context : Any> Value<Context, String?>.trimStart(characters: Value<Context, String?>): Value<Context, String?>

Removes the specified characters from the beginning of a string.

unsafe

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: String): Field<Root, Child>

Refers to a field child of the current field, with no compile-time safety.

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: KProperty1<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: Field<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Child> Field<Root, *>.unsafe(child: KProperty1<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Child> Field<Root, *>.unsafe(child: Field<*, Child>): Field<Root, Child>

Refers to a field child of the current field, without checking that it is a field available on the current object.

open infix fun <Root, Type, Child> Field<Root, Type>.unsafe(child: String): Field<Root, Child>

Refers to a field child of the current field, with no compile-time safety.

uppercase

Converts a string to uppercase, returning the result.

writeTo

@LowLevelApi



abstract override fun writeTo(writer: BsonFieldWriter)

Writes the result of simplifying this expression into writer.