MongoDB request DSL • opensavvy.ktmongo.dsl.aggregation.operators • TypeValueOperators • toBoolean
toBoolean¶
Converts this value to a BsonType.Boolean.
Conversion algorithm¶
BsonType.Boolean is returned as itself.
Numeric types (BsonType.Int32, BsonType.Int64, BsonType.Double and BsonType.Decimal128) consider that 0 is false
and all other values are true
.
BsonType.Null always returns null
.
All other types always return true
.
Example¶
class User(
val foo: String
)
users.aggregate()
.project {
Field.unsafe<Boolean>("asBoolean") set of(User::foo).toBoolean()
}
External resources¶
See also¶
TypeValueOperators.type
Get the value's type.