Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.aggregation.operatorsArrayValueOperatorstake

take

Returns the first limit elements in an array, similar to kotlin.collections.take.

Example

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

players.updateManyWithPipeline {
    set {
        Player::firstScores set Player::scores.take(3)
    }
}

External resources

Returns the first limit elements in an array, similar to kotlin.collections.take.

Example

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

players.updateManyWithPipeline {
    set {
        Player::firstScores set Player::scores.take(3)
    }
}

External resources

Returns the first limit elements in an array, similar to kotlin.collections.take.

Example

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

players.updateManyWithPipeline {
    set {
        Player::firstScores set Player::scores.take(3)
    }
}

External resources

open fun <Context : Any, T> Collection<T>.take(limit: Value<Context, Number>): Value<Context, List<T>>

Returns the first limit elements in an array, similar to kotlin.collections.take.

Example

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

players.updateManyWithPipeline {
    set {
        Player::firstScores set Player::scores.take(3)
    }
}

External resources