filter

open fun <Context : Any, T> Value<Context, Collection<T>>.filter(limit: Value<Context, Number>? = null, variableName: String = "this", predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>): Value<Context, List<T>>(source)
open fun <Context : Any, T> Field<Context, Collection<T>>.filter(limit: Value<Context, Number>? = null, variableName: String = "this", predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>): Value<Context, List<T>>(source)
open fun <Context : Any, T> KProperty1<Context, Collection<T>>.filter(limit: Value<Context, Number>? = null, variableName: String = "this", predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>): Value<Context, List<T>>(source)
open fun <Context : Any, T> Collection<T>.filter(limit: Value<Context, Number>? = null, variableName: String = "this", predicate: AggregationOperators.(Value<Any, T>) -> Value<T & Any, Boolean>): Value<Context, List<T>>(source)

Selects a subset of an array to return based on the specified predicate, similarly to kotlin.collections.filter.

The returned elements are in the original order.

Example

class Sensor(
val measurements: List<Int>,
)

collection.updateManyWithPipeline {
set {
Sensor::measurements set (Sensor::measurements).filter { it gte of(0) }
}
}

External resources

Parameters

limit

If set, specifies a maximum number of elements returned: only the first limit matching elements are returned, even if there are more matching elements. Must be greater or equal to 1, or be null.

variableName

The name of the temporary variable passed to the predicate lambda, which represents the current element being iterated over. By default, "this". Setting this parameter is only useful when using nested filter or other similar calls, which could otherwise conflict.