Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryFilterQueryisMapEmpty

isMapEmpty

open fun Field<T, Map<String, *>>.isMapEmpty()

Matches documents in which a map is empty or absent.

Example

Return all users that have no grades (either an empty map, or the grades field is absent):

class User(
    val name: String?,
    val grades: Map<String, Int>
)

collection.find {
    User::grades.isMapEmpty()
}

See also

open fun KProperty1<T, Map<String, *>>.isMapEmpty()

Matches documents in which a map is empty or absent.

Example

Return all users that have no grades (either an empty map, or the grades field is absent):

class User(
    val name: String?,
    val grades: Map<String, Int>
)

collection.find {
    User::grades.isMapEmpty()
}

See also