ArrayValueOperators¶
interface ArrayValueOperators : ValueOperators
Operators to manipulate arrays.
To learn more about aggregation operators, see opensavvy.ktmongo.dsl.aggregation.AggregationOperators.
Inheritors¶
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.
Functions¶
average¶
open fun <Context : Any, T : Number> Value<Context, Collection<Number?>>.average(): Value<Context, T>
@JvmName(name = "averageFieldReceiver")
open fun <Context : Any, T : Number> Field<Context, Collection<Number?>>.average(): Value<Context, T>
@JvmName(name = "averagePropertyReceiver")
open fun <Context : Any, T : Number> KProperty1<Context, Collection<Number?>>.average(): Value<Context, T>
@JvmName(name = "averageResultReceiver")
open fun <Context : Any, T : Number> Collection<Number?>.average(): Value<Context, T>
open fun <Context : Any, T : Number> average(vararg input: Value<Context, Number?>): Value<Context, T>
Deprecated (with error)
Computing the average of 0 elements makes no sense, you should specify the elements to average as the receiver or as arguments.
div¶
open operator fun <Context : Any, Root, Child> Value<Context, Root>.div(field: Field<Root, Child>): Value<Context, Child>
@JvmName(name = "divFieldReceiver")
open operator fun <Context : Any, Root, Child> Field<Context, Root>.div(field: Field<Root, Child>): Value<Context, Child>
@JvmName(name = "divResultReceiver")
inline operator fun <Context : Any, Root, Child> Root.div(field: Field<Root, Child>): Value<Context, Child>
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.
Examples
class User(
val name: String,
)
class Data(
val users: List<User>,
val userNames: List<Int>,
)
data.aggregate()
.set {
Data::userNames set Data::users.map { it / User::name }
}
External resources
filter¶
open fun <Context : Any, T> Value<Context, Collection<T>>.filter(
limit: Value<Context, Int>? = null,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterByField")
open fun <Context : Any, T> Value<Context, Collection<T>>.filter(
limit: Field<Context, Int>,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterByProperty")
open fun <Context : Any, T> Value<Context, Collection<T>>.filter(
limit: KProperty1<Context, Int>,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
open fun <Context : Any, T> Value<Context, Collection<T>>.filter(
limit: Int,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterFieldReceiverByValue")
open fun <Context : Any, T> Field<Context, Collection<T>>.filter(
limit: Value<Context, Int>? = null,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterFieldReceiverByField")
open fun <Context : Any, T> Field<Context, Collection<T>>.filter(
limit: Field<Context, Int>,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterFieldReceiverByProperty")
open fun <Context : Any, T> Field<Context, Collection<T>>.filter(
limit: KProperty1<Context, Int>,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterFieldReceiverByResult")
open fun <Context : Any, T> Field<Context, Collection<T>>.filter(
limit: Int,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterPropertyReceiverByValue")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.filter(
limit: Value<Context, Int>? = null,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterPropertyReceiverByField")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.filter(
limit: Field<Context, Int>,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterPropertyReceiverByProperty")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.filter(
limit: KProperty1<Context, Int>,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterPropertyReceiverByResult")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.filter(
limit: Int,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterResultReceiverByValue")
open fun <Context : Any, T> Collection<T>.filter(
limit: Value<Context, Int>? = null,
variableName: String = "this",
predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>
): Value<Context, List<T>>
@JvmName(name = "filterResultReceiverByField")
open fun <Context : Any, T> Collection<T>.filter(
limit: Field<Context, Int>,
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``.
The returned elements are in the original order.
Example
class Sensor(
val measurements: List<Int>,
)
collection.updateManyWithPipeline {
set {
Sensor::measurements set (Sensor::measurements).filter { it gte of(0) }
}
}
External resources
Parameters
-
limit: If set, specifies a maximum number of elements returned: only the first
limitmatching elements are returned, even if there are more matching elements. Must be greater or equal to1, or benull. -
variableName: The name of the temporary variable passed to the
predicatelambda, which represents the current element being iterated over. By default,"this". Setting this parameter is only useful when using nestedfilteror other similar calls, which could otherwise conflict.
get¶
Refers to a specific item in an array, by its index.
Refers to a specific item in a map, by its name.
Refers to a specific item in an array, by its index.
Refers to a specific item in a map, by its name.
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>>
@JvmName(name = "mapFieldReceiver")
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.
Example
class Player(
val _id: ObjectId,
val scores: List<Int>,
)
players.updateManyWithPipeline {
set {
Player::scores set Player::scores
.map {
it + of(1)
}
}
}
External resources
of¶
Refers to a field within an aggregation value.
Example
Refers to a Kotlin value within an aggregation value.
Example
Refers to a BsonType within an aggregation value.
Example
sorted¶
@JvmName(name = "sortedFieldReceiver")
open fun <Context : Any, T> Field<Context, Collection<T>>.sorted(): Value<Context, List<T>>
Sorts an array based on its elements, in ascending order.
Example
class Player(
val _id: ObjectId,
val scores: List<Int>,
val worstScores: List<Int>,
)
players.updateManyWithPipeline {
set {
Player::bestScores set Player::scores
.sorted()
.take(5)
}
}
External resources
See also
-
sortedBy: Sort by fields of elements. -
sortedDescending: Sort by elements in descending order.
sortedBy¶
open fun <Context : Any, T> Value<Context, Collection<T>>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>
@JvmName(name = "sortedByFieldReceiver")
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.
Example
class Score(
val value: Int,
)
class Player(
val _id: ObjectId,
val scores: List<Score>,
val bestScores: List<Score>,
)
players.updateManyWithPipeline {
set {
Player::bestScores set Player::scores
.sortedBy { ascending(Score::value) }
}
}
External resources
See also
-
sorted: Sort by the elements themselves (ascending order). -
sortedDescending: Sort by the elements themselves (descending order).
sortedDescending¶
open fun <Context : Any, T> Value<Context, Collection<T>>.sortedDescending(): Value<Context, List<T>>
@JvmName(name = "sortedDescendingFieldReceiver")
open fun <Context : Any, T> Field<Context, Collection<T>>.sortedDescending(): Value<Context, List<T>>
@JvmName(name = "sortedDescendingPropertyReceiver")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.sortedDescending(): Value<Context, List<T>>
Sorts an array based on its elements, in descending order.
Example
class Player(
val _id: ObjectId,
val scores: List<Int>,
val bestScores: List<Int>,
)
players.updateManyWithPipeline {
set {
Player::bestScores set Player::scores
.sortedDescending()
.take(5)
}
}
External resources
See also
-
sortedBy: Sort by fields of elements. -
sortedDescending: Sort by fields of elements.
take¶
open fun <Context : Any, T> Value<Context, Collection<T>>.take(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeByField")
open fun <Context : Any, T> Value<Context, Collection<T>>.take(limit: Field<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeByProperty")
open fun <Context : Any, T> Value<Context, Collection<T>>.take(limit: KProperty1<Context, Int>): Value<Context, List<T>>
inline fun <Context : Any, T> Value<Context, Collection<T>>.take(limit: Int): Value<Context, List<T>>
@JvmName(name = "takeFieldReceiverByValue")
open fun <Context : Any, T> Field<Context, Collection<T>>.take(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeFieldReceiverByField")
open fun <Context : Any, T> Field<Context, Collection<T>>.take(limit: Field<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeFieldReceiverByProperty")
open fun <Context : Any, T> Field<Context, Collection<T>>.take(limit: KProperty1<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeFieldReceiverByResult")
inline fun <Context : Any, T> Field<Context, Collection<T>>.take(limit: Int): Value<Context, List<T>>
@JvmName(name = "takePropertyReceiverByValue")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.take(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takePropertyReceiverByField")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.take(limit: Field<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takePropertyReceiverByProperty")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.take(limit: KProperty1<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takePropertyReceiverByResult")
inline fun <Context : Any, T> KProperty1<Context, Collection<T>>.take(limit: Int): Value<Context, List<T>>
@JvmName(name = "takeResultReceiverByValue")
open fun <Context : Any, T> Collection<T>.take(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeResultReceiverByField")
open fun <Context : Any, T> Collection<T>.take(limit: Field<Context, Int>): Value<Context, List<T>>
Returns the first limit elements in an array, similar to kotlin.collections.take.
Example
class Player(
val _id: ObjectId,
val scores: List<Int>,
val firstScores: List<Int>,
)
players.updateManyWithPipeline {
set {
Player::firstScores set Player::scores.take(3)
}
}
External resources
takeLast¶
open fun <Context : Any, T> Value<Context, Collection<T>>.takeLast(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastByField")
open fun <Context : Any, T> Value<Context, Collection<T>>.takeLast(limit: Field<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastByProperty")
open fun <Context : Any, T> Value<Context, Collection<T>>.takeLast(limit: KProperty1<Context, Int>): Value<Context, List<T>>
inline fun <Context : Any, T> Value<Context, Collection<T>>.takeLast(limit: Int): Value<Context, List<T>>
@JvmName(name = "takeLastFieldReceiverByValue")
open fun <Context : Any, T> Field<Context, Collection<T>>.takeLast(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastFieldReceiverByField")
open fun <Context : Any, T> Field<Context, Collection<T>>.takeLast(limit: Field<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastFieldReceiverByProperty")
open fun <Context : Any, T> Field<Context, Collection<T>>.takeLast(limit: KProperty1<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastFieldReceiverByResult")
inline fun <Context : Any, T> Field<Context, Collection<T>>.takeLast(limit: Int): Value<Context, List<T>>
@JvmName(name = "takeLastPropertyReceiverByValue")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.takeLast(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastPropertyReceiverByField")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.takeLast(limit: Field<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastPropertyReceiverByProperty")
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.takeLast(limit: KProperty1<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastPropertyReceiverByResult")
inline fun <Context : Any, T> KProperty1<Context, Collection<T>>.takeLast(limit: Int): Value<Context, List<T>>
@JvmName(name = "takeLastResultReceiverByValue")
open fun <Context : Any, T> Collection<T>.takeLast(limit: Value<Context, Int>): Value<Context, List<T>>
@JvmName(name = "takeLastResultReceiverByField")
open fun <Context : Any, T> Collection<T>.takeLast(limit: Field<Context, Int>): Value<Context, List<T>>
Returns the last limit elements in an array, similar to kotlin.collections.takeLast.
Example
class Player(
val _id: ObjectId,
val scores: List<Int>,
val lastScores: List<Int>,
)
players.updateManyWithPipeline {
set {
Player::lastScores set Player::scores.takeLast(3)
}
}
External resources
unsafe¶
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.
Refers to a field child of the current field, without checking that it is a field available on the current object.
Refers to a field child of the current field, without checking that it is a field available on the current object.
Refers to a field child of the current field, without checking that it is a field available on the current object.