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¶
Returns the average of the elements in the array.
Example¶
class Player(
val _id: ObjectId,
val scores: List<Int>,
val averageScore: Double,
)
players.updateManyWithPipeline {
set {
Player::averageScore set Player::scores.average()
}
}
External resources¶
Returns the average of the elements in the array.
Example¶
class Player(
val _id: ObjectId,
val scores: List<Int>,
val averageScore: Double,
)
players.updateManyWithPipeline {
set {
Player::averageScore set Player::scores.average()
}
}
External resources¶
Returns the average of the elements in the array.
Example¶
class Player(
val _id: ObjectId,
val scores: List<Int>,
val averageScore: Double,
)
players.updateManyWithPipeline {
set {
Player::averageScore set Player::scores.average()
}
}
External resources¶
Returns the average of the elements in the array.
Example¶
class Player(
val _id: ObjectId,
val scores: List<Int>,
val averageScore: Double,
)
players.updateManyWithPipeline {
set {
Player::averageScore set Player::scores.average()
}
}
External resources¶
Returns the average of the elements in the array.
Example¶
class Player(
val _id: ObjectId,
val scores: List<Int>,
val averageScore: Double,
)
players.updateManyWithPipeline {
set {
Player::averageScore set Player::scores.average()
}
}
External resources¶
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¶
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¶
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¶
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.
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.
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.
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¶
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¶
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¶
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¶
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 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¶
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by elements in descending order.
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by elements in descending order.
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by elements in descending order.
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by elements in descending order.
sortedBy¶
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
-
ArrayValueOperators.sorted: Sort by the elements themselves (ascending order). -
ArrayValueOperators.sortedDescending: Sort by the elements themselves (descending order).
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
-
ArrayValueOperators.sorted: Sort by the elements themselves (ascending order). -
ArrayValueOperators.sortedDescending: Sort by the elements themselves (descending order).
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
-
ArrayValueOperators.sorted: Sort by the elements themselves (ascending order). -
ArrayValueOperators.sortedDescending: Sort by the elements themselves (descending order).
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
-
ArrayValueOperators.sorted: Sort by the elements themselves (ascending order). -
ArrayValueOperators.sortedDescending: Sort by the elements themselves (descending order).
sortedDescending¶
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by fields of elements.
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by fields of elements.
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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by fields of elements.
open fun <Context : Any, T> 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
-
ArrayValueOperators.sortedBy: Sort by fields of elements. -
ArrayValueOperators.sortedDescending: Sort by fields of elements.
take¶
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¶
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¶
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¶
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¶
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¶
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¶
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¶
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.
Refers to a field child of the current field, with no compile-time safety.