Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryFilterQueryPredicatehasType

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