Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.aggregation.operatorsArrayValueOperatorsmap

map

open fun <Context : Any, T, R> Value<Context, Collection<T>>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
)

players.updateManyWithPipeline {
    set {
        Player::scores set Player::scores
            .map {
                it + of(1)
            }
    }
}

External resources

open fun <Context : Any, T, R> Field<Context, Collection<T>>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
)

players.updateManyWithPipeline {
    set {
        Player::scores set Player::scores
            .map {
                it + of(1)
            }
    }
}

External resources

open fun <Context : Any, T, R> KProperty1<Context, Collection<T>>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
)

players.updateManyWithPipeline {
    set {
        Player::scores set Player::scores
            .map {
                it + of(1)
            }
    }
}

External resources

open fun <Context : Any, T, R> Collection<T>.map(variableName: String = "this", transform: AggregationOperators.(Value<Any, T>) -> Value<Context, R>): Value<Context, List<R>>

Applies a transform to all elements in an array and returns the array with the applied results, similar to kotlin.collections.map.

Example

class Player(
    val _id: ObjectId,
    val scores: List<Int>,
)

players.updateManyWithPipeline {
    set {
        Player::scores set Player::scores
            .map {
                it + of(1)
            }
    }
}

External resources