pushEach

open fun <V> Field<T, Collection<V>>.pushEach(values: Iterable<V>, type: KType)(source)
infix inline fun <V> Field<T, Collection<V>>.pushEach(values: Iterable<V>)(source)
infix inline fun <V> KProperty1<T, Collection<V>>.pushEach(values: Iterable<V>)(source)

Adds multiple values at the end of the array.

Unlike addToSet, this operator always adds all values, even if they're already present in the array.

This is a convenience function for calling push multiple times.

Example

class User(
val name: String,
val age: Int,
val scores: List<Int>,
)

collection.updateOne(
filter = {
User::name eq "Bob"
},
update = {
User::scores pushEach listOf(100, 200)
}
)

This will add 100 and 200 to the user's scores, even if they're already present.

External resources