MongoDB request DSL • opensavvy.ktmongo.dsl.query • FilterQueryPredicate • hasType
hasType¶
abstract fun hasType(type: ERROR CLASS: Symbol not found for BsonType)
Selects documents where the value of the field is an instance of the specified BSON type.
Querying by data type is useful when dealing with highly unstructured data where data types are not predictable.
Example¶
class User(
val name: String,
val age: Any,
)
collection.find {
User::age {
type(BsonType.STRING)
}
}
External resources¶
See also¶
-
FilterQuery.hasTypeShorthand. -
FilterQueryPredicate.isNullChecks if a value has the type BsonType.Null. -
FilterQueryPredicate.isUndefinedChecks if a value has the type BsonType.Undefined.