anyValue

abstract fun <V> Field<T, Collection<V>>.anyValue(block: FilterQueryPredicate<V>.() -> Unit)(source)

Specify multiple operators on a single array element.

Example

Find students with a grade between 8 and 10, that may be eligible to perform an exam a second time.

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

collection.find {
Student::grades.anyValue {
gte(8)
lte(10)
}
}

The following document will match because the grade 9 is in the interval.

{
"name": "John",
"grades": [9, 3]
}

The following document will NOT match, because none of the grades are in the interval.

{
"name": "Lea",
"grades": [18, 19]
}

If you want to perform multiple checks on different elements of an array, see the any property.

This function only allows specifying operators on array elements directly. To specify operators on sub-fields of array elements, see any.

External resources