Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.queryFilterQuerysize

size

abstract infix fun Field<T, Collection<*>>.size(size: Int)

Selects documents where the value of a field is an array of size size (exactly).

This operator cannot accept a range of values. To select documents based on fields with different numbers of elements, create a counter field that you increment when you add elements to a field.

Queries cannot use indexes for this portion of the query, but other parts of the query may use indexes if applicable.

Example

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

collection.find {
    User::grades size 3
}

External resources

open infix fun KProperty1<T, Collection<*>>.size(size: Int)

Selects documents where the value of a field is an array of size size (exactly).

This operator cannot accept a range of values. To select documents based on fields with different numbers of elements, create a counter field that you increment when you add elements to a field.

Queries cannot use indexes for this portion of the query, but other parts of the query may use indexes if applicable.

Example

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

collection.find {
    User::grades size 3
}

External resources