ascending

abstract fun ascending(field: Field<Document, *>)(source)
open fun ascending(field: KProperty1<Document, *>)(source)

If two documents have a different value of field, the one with lesser value will be returned first.

If this function is called multiple times, the first call takes precedence: subsequent calls determine the order of documents when they are equal according to the first call.

Example

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

users.find(
options = {
sort {
ascending(User::age)
ascending(User::name)
}
},
filter = {}
)

This will return users from the youngest to the oldest. If multiple users have the same age, they are returned in the alphabetical order of their name.

See also

To return documents in descending order.