Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryFilterQueryhasType

hasType

open infix fun Field<T, *>.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 hasType BsonType.STRING
}

External resources

See also

open infix fun KProperty1<T, *>.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 hasType BsonType.STRING
}

External resources

See also