Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryFilterQueryisEmpty

isEmpty

open fun Field<T, Collection<*>>.isEmpty()

Matches documents in which an array is empty or absent.

Example

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

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

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

See also

open fun KProperty1<T, Collection<*>>.isEmpty()

Matches documents in which an array is empty or absent.

Example

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

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

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

See also