toLong
Converts this value to an Long (BsonType.Int64).
Conversion algorithm
BsonType.Int64 is returned as itself.
BsonType.Int32 is extended to a Long.
BsonType.Boolean becomes 1 if true
and 0 if false
.
BsonType.Double and BsonType.Decimal128 are truncated to an integer value. If this value does not fall in the valid range for a long, an exception is thrown.
BsonType.String is parsed as a double. Only base 10 numbers can be parsed. If the value is outside the range of a double, an exception is thrown. "-5"
and "123456"
are two valid examples. Floating-point numbers are not supported (use toDouble).
BsonType.Datetime returns the number of milliseconds since the epoch.
BsonType.Null always returns null
.
Other types throw an exception.
Example
class Product(
val quantity: Double,
)
users.aggregate()
.set {
Field.unsafe<Long>("quantity") set of(Product::quantity).toLong()
}
Content copied to clipboard
External resources
See also
Get the value's type.