Skip to content

MongoDB request DSLopensavvy.ktmongo.dsl.aggregation.operatorsArrayValueOperatorstakeLast

takeLast

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Example

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

players.updateManyWithPipeline {
    set {
        Player::lastScores set Player::scores.takeLast(3)
    }
}

External resources

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Example

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

players.updateManyWithPipeline {
    set {
        Player::lastScores set Player::scores.takeLast(3)
    }
}

External resources

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Example

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

players.updateManyWithPipeline {
    set {
        Player::lastScores set Player::scores.takeLast(3)
    }
}

External resources

Returns the last limit elements in an array, similar to kotlin.collections.takeLast.

Example

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

players.updateManyWithPipeline {
    set {
        Player::lastScores set Player::scores.takeLast(3)
    }
}

External resources