ArithmeticValueOperators¶
interface ArithmeticValueOperators : ValueOperators
Operators to arithmetically combine two or more values.
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¶
abs¶
The absolute value of a number.
If the value is null or NaN, it is returned unchanged.
Example¶
class Sensor(
val name: String,
val startTemp: Int,
val endTemp: Int,
val diffTemp: Int,
)
collection.updateManyWithPipeline(filter = { Sensor::diffTemp.isNull() }) {
set {
Sensor::diffTemp set abs(of(Sensor::startTemp) - of(Sensor::endTemp))
}
}
External resources¶
ceil¶
The smallest integer greater than or equal to the specified value.
If the value is null or NaN, it is returned unchanged.
Example¶
class Sensor(
val value: Double,
val maxBound: Double,
)
collection.aggregate()
.set {
Sensor::maxBound set ceil(of(Sensor::value))
}.toList()
External resources¶
div¶
Divides one aggregation value by another.
Example¶
class ConferencePlanning(
val hours: Int,
val workdays: Double,
)
collection.updateManyWithPipeline {
set {
ConferencePlanning::workdays set (of(ConferencePlanning::hours) / of(8))
}
}
External resources¶
floor¶
The largest integer less than or equal to the specified value.
If the value is null or NaN, it is returned unchanged.
Example¶
class Sensor(
val value: Double,
val minBound: Double,
)
collection.aggregate()
.set {
Sensor::minBound set floor(of(Sensor::value))
}.toList()
External resources¶
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.
minus¶
Subtracts one aggregation value from another.
The second argument is subtracted from the first argument.
Example¶
class Sale(
val price: Int,
val fee: Int,
val discount: Int,
val total: Int,
)
collection.updateManyWithPipeline {
set {
Sale::total set (of(Sale::price) + of(Sale::fee) - of(Sale::discount))
}
}
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¶
plus¶
Sums two aggregation values.
Example¶
class Product(
val name: String,
val price: Int,
val dailyPriceIncrease: Int,
)
collection.updateManyWithPipeline {
set {
Product::price set (of(Product::price) + of(Product::dailyPriceIncrease))
}
}
External resources¶
times¶
Multiplies two or more aggregation values.
Example¶
class Sale(
val price: Double,
val quantity: Int,
val total: Double,
)
collection.updateManyWithPipeline {
set {
Sale::total set (of(Sale::price) * of(Sale::quantity))
}
}
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.