Skip to content

TrigonometryValueOperators

Operators to perform trigonometric and geometric operators.

To learn more about aggregation operators, see 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

acos

open fun <Context : Any> acos(value: Value<Context, Double?>): Value<Context, Double?>

The inverse cosine (arc cosine) of a value, in radians.

The value must be in the range -1..1.

If the value is null or NaN, it is returned unchanged.

Example
class Triangle(
    val name: String,
    val sideA: Double,
    val sideB: Double,
    val hypotenuse: Double,
    val angleA: Double,
)

collection.aggregate()
    .set {
        Triangle::angleA set acos(of(Triangle::sideB) / of(Triangle::hypotenuse))
    }
External resources

acosh

open fun <Context : Any> acosh(value: Value<Context, Double?>): Value<Context, Double?>

The inverse hyperbolic cosine (hyperbolic arc cosine) of a value, in radians.

The value must be in the range 1..∞.

If the value is null or NaN, it is returned unchanged.

Example
class Trigonometry(
    val name: String,
    val x: Double,
    val y: Double,
)

collection.aggregate()
    .set {
        Trigonometry::y set acosh(of(Trigonometry::x))
    }
External resources

asin

open fun <Context : Any> asin(value: Value<Context, Double?>): Value<Context, Double?>

The inverse sine (arc sine) of a value, in radians.

The value must be in the range -1..1.

If the value is null or NaN, it is returned unchanged.

Example
class Triangle(
    val name: String,
    val sideA: Double,
    val sideB: Double,
    val hypotenuse: Double,
    val angleA: Double,
)

collection.aggregate()
    .set {
        Triangle::angleA set asin(of(Triangle::sideA) / of(Triangle::hypotenuse))
    }
External resources

asinh

open fun <Context : Any> asinh(value: Value<Context, Double?>): Value<Context, Double?>

The inverse hyperbolic sine (hyperbolic arc sine) of a value, in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Trigonometry(
    val name: String,
    val x: Double,
    val y: Double,
)

collection.aggregate()
    .set {
        Trigonometry::y set asinh(of(Trigonometry::x))
    }
External resources

atan

open fun <Context : Any> atan(value: Value<Context, Double?>): Value<Context, Double?>

The inverse tangent (arc tangent) of a value, in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Triangle(
    val name: String,
    val sideA: Double,
    val sideB: Double,
    val hypotenuse: Double,
    val angleA: Double,
)

collection.aggregate()
    .set {
        Triangle::angleA set atan(of(Triangle::sideB) / of(Triangle::sideA))
    }
External resources

atanh

open fun <Context : Any> atanh(value: Value<Context, Double?>): Value<Context, Double?>

The inverse hyperbolic tangent (hyperbolic arc tangent) of a value, in radians.

The value must be in the range -1..1.

If the value is null or NaN, it is returned unchanged.

Example
class Trigonometry(
    val name: String,
    val x: Double,
    val y: Double,
)

collection.aggregate()
    .set {
        Trigonometry::y set atanh(of(Trigonometry::x))
    }
External resources

cos

open fun <Context : Any> cos(value: Value<Context, Double?>): Value<Context, Double?>

The cosine of a value that is measured in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Triangle(
    val name: String,
    val sideA: Double,
    val sideB: Double,
    val hypotenuse: Double,
    val angleA: Double,
)

collection.aggregate()
    .set {
        Triangle::sideB set (of(cos(Triangle::angleA) * of(Triangle::hypotenuse)))
    }
External resources

cosh

open fun <Context : Any> cosh(value: Value<Context, Double?>): Value<Context, Double?>

The hyperbolic cosine of a value that is measured in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Trigonometry(
    val name: String,
    val angle: Double,
    val cosh: Double,
)

collection.aggregate()
    .set {
        Trigonometry::cosh set cosh(of(Trigonometry::angle))
    }
External resources

div

open operator fun <Context : Any, Root, Child> Value<Context, Root>.div(field: Field<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
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

get

open operator fun <Root, Type> KProperty1<Root, Collection<Type>>.get(index: Int): Field<Root, Type>

Refers to a specific item in an array, by its index.

open operator fun <Root, Type> KProperty1<Root, Map<String, Type>>.get(index: String): Field<Root, Type>

Refers to a specific item in a map, by its name.

open operator fun <Root, Type> Field<Root, Collection<Type>>.get(index: Int): Field<Root, Type>

Refers to a specific item in an array, by its index.

open operator fun <Root, Type> Field<Root, Map<String, Type>>.get(key: String): Field<Root, Type>

Refers to a specific item in a map, by its name.

of

open fun <Context : Any, Result> of(field: Field<Context, Result>): Value<Context, Result>

Refers to a field within an aggregation value.

Example
class Product(
    val acceptanceDate: Instant,
    val publishingDate: Instant,
)

val publishedBeforeAcceptance = products.find {
    expr {
        of(Product::publishingDate) lt of(Product::acceptanceDate)
    }
}

Refers to a field within an aggregation value.

Example
class Product(
    val acceptanceDate: Instant,
    val publishingDate: Instant,
)

val publishedBeforeAcceptance = products.find {
    expr {
        of(Product::publishingDate) lt of(Product::acceptanceDate)
    }
}
open fun <Result> of(value: Result): Value<Any, Result>

Refers to a Kotlin value within an aggregation value.

Example
class Product(
    val age: Int,
)

val publishedBeforeAcceptance = products.find {
    expr {
        of(Product::age) lt of(15)
    }
}
open fun of(value: BsonType): Value<Any, BsonType>

Refers to a BsonType within an aggregation value.

Example
class Product(
    val age: Int,
)

val publishedBeforeAcceptance = products.find {
    expr {
        of(Product::age).type eq of(BsonType.Int32)
    }
}

sin

open fun <Context : Any> sin(value: Value<Context, Double?>): Value<Context, Double?>

The sine of a value that is measured in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Triangle(
    val name: String,
    val sideA: Double,
    val sideB: Double,
    val hypotenuse: Double,
    val angleA: Double,
)

collection.aggregate()
    .set {
        Triangle::sideB set (sin(of(Trigonometry::angleA)) * of(Trigonometry::hypotenuse))
    }
External resources

sinh

open fun <Context : Any> sinh(value: Value<Context, Double?>): Value<Context, Double?>

The hyperbolic sine of a value that is measured in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Trigonometry(
    val name: String,
    val x: Double,
    val y: Double,
)

collection.aggregate()
    .set {
        Trigonometry::y set sinh(of(Trigonometry::x))
    }
External resources

tan

open fun <Context : Any> tan(value: Value<Context, Double?>): Value<Context, Double?>

The tangent of a value that is measured in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Triangle(
    val name: String,
    val sideA: Double,
    val sideB: Double,
    val hypotenuse: Double,
    val angleA: Double,
)

collection.aggregate()
    .set {
        Triangle::sideB set (tan(of(Trigonometry::angleA) * of(Trigonometry::sideA)))
    }
External resources

tanh

open fun <Context : Any> tanh(value: Value<Context, Double?>): Value<Context, Double?>

The hyperbolic tangent of a value that is measured in radians.

If the value is null or NaN, it is returned unchanged.

Example
class Trigonometry(
    val name: String,
    val x: Double,
    val y: Double,
)

collection.aggregate()
    .set {
        Trigonometry::y set tanh(of(Trigonometry::x))
    }
External resources

toDegrees

Converts an angle in radians to an angle in degrees.

Example
class Trigonometry(
    val angleADeg: Double,
    val angleARad: Double,
)

collection.updateManyWithPipeline {
    set {
        Trigonometry::angleADeg set of(Trigonometry::angleARad).toDegrees()
    }
}
External resources

See also

toRadians

Converts an angle in degrees to an angle in radians.

Example
class Trigonometry(
    val angleADeg: Double,
    val angleARad: Double,
)

collection.updateManyWithPipeline {
    set {
        Trigonometry::angleARad set of(Trigonometry::angleADeg).toRadians()
    }
}
External resources

See also

unsafe

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: String): Field<Root, Child>

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.

open infix fun <Root, Child> KProperty1<Root, *>.unsafe(child: Field<*, 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.

open infix fun <Root, Child> Field<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.

open infix fun <Root, Child> Field<Root, *>.unsafe(child: Field<*, 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.

open infix fun <Root, Type, Child> Field<Root, Type>.unsafe(child: String): Field<Root, Child>

Refers to a field child of the current field, with no compile-time safety.