sortedBy
open fun <Context : Any, T> Value<Context, Collection<T>>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>(source)
open fun <Context : Any, T> Field<Context, Collection<T>>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>(source)
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>(source)
open fun <Context : Any, T> Collection<T>.sortedBy(order: SortOptionDsl<T & Any>.() -> Unit): Value<Context, List<T>>(source)
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) }
}
}
Content copied to clipboard
External resources
See also
Sort by the elements themselves (ascending order).
Sort by the elements themselves (descending order).