Skip to content

SortOption

Describes in which order elements should be returned.

For more information, see WithSort.sort.

External resources

Constructors

SortOption

constructor(config: SortOptionDsl<Document>, context: BsonContext)

Properties

block

The sort option's configured block.

In this block, each field is the declaration of a sort criterion.

context

@LowLevelApi
open override val context: BsonContext

The context used to generate this expression.

name

open override val name: String

The name of this option, as it appears in the BSON representation.

Options always have the form:

find(
    {
        "limit": 10,
        "sort": { }
    },
    { }
)

In this example, the LimitOption has the name "limit" and the SortOption has the name "sort".

Implementation notes

This value should be immutable.

Functions

freeze

@LowLevelApi
open override fun freeze()

Makes this node immutable.

merge

@LowLevelApi
open override fun merge(other: Option): Option

Merges this option with another of the same type.

The caller is responsible for only calling this method with a parameter of the same concrete type as the current instance.

This method returns a new option, which combines the values of both options.

This method must be called in the same order as the options are defined. For example, if a is defined before b, then a.merge(b) is valid, but b.merge(a) is not.

By default, this method returns the last declared option.

This method is called by the option holder's BsonNode.simplify method.

read

@LowLevelApi
override fun read(): BsonValue

Reads the value of this option.

Performance

Note that this method requires to write this option into a temporary BSON value.

simplify

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

Returns null when the current expression was simplified into a no-op (= it does nothing).

toBson

Writes the result of simplifying to a new BsonDocument.

toString

override fun toString(): String

JSON representation of this expression.

fun toString(simplified: Boolean): String

JSON representation of this expression.

writeTo

@LowLevelApi
override fun writeTo(writer: BsonFieldWriter)

Writes the result of simplifying this expression into writer.